图表多类型和辅助Y轴 [英] Charts multi type and secondary Y axis

查看:169
本文介绍了图表多类型和辅助Y轴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个图表,其中有3个系列,2是列,我需要一条通过它显示平均线。

I'm creating a chart which had 3 series, 2 which are columns, and I need a line which runs through which shows the average.

趋势线,但是当我只想看到趋势线时,我的图表显示一系列列和趋势线。以下是代码:

I have found trendlines but at the moment my chart is showing a series column and a trendline when I just want to see the trend line. Here is the code:

// Add a chart for the country. i.e. show the 
var chart = worksheet.Drawings.AddChart(countryName + "Click through report", eChartType.ColumnClustered);

// Set the size of the chart
chart.SetSize(1150, 540);

//Set the series value for each column - impressions
int chartrange = cumCtrj + 27;
var series1 = chart.Series.Add("=" + countryName + "!$B$29:$B$" + chartrange, "=" + countryName + "!$A$29:$A$" + chartrange);
series1.Header = "Dealer Lists Displayed";

// column - Clicks
var series2 = chart.Series.Add("=" + countryName + "!$C$29:$C$" + chartrange, "=" + countryName + "!$A$29:$A$" + chartrange);
series2.Header = "Clicks To Dealer";

var series3 = chart.Series.Add("=" + countryName + "!$D$29:$D$" + chartrange, "=" + countryName + "!$A$29:$A$" + chartrange);
series3.Header = "Click Through Rate";
series3.TrendLines.Add(eTrendLine.Linear);

如何在没有列的情况下获得趋势线?

How can I just have the trendline without the column?

编辑:我实际上不确定它是我需要的趋势线 - 因为值实际上是在表中(CTR率是点击/曝光* 100,是一个百分比值) - 但我需要显示为通过其他两列的一行。

I'm not actually certain that it is trendlines that i need - as the values are actually in the table (- the CTR rate is the clicks/impressions* 100 and is a percentage value) - but i need this shown as a line going through the other two columns.

下面是我工作的表的示例。

Below is an example of the table that i am working from.

Row Impressions Clicks CTR

40  391 4   1.0210593
41  986 35  3.5491558
42  104 37  3.534818
43  236 38  16.064257
44  579 10  1.72592337

编辑2:
找到了添加行的方法(因此第二个图表类型到我的图表中请看下面的代码:

EDIT 2: I have found the way to add a line (so a second chart type to my chart please see the following code:

   // TODO click through rate as a line.
                            var chartType2 = chart.PlotArea.ChartTypes.Add(eChartType.Line);
                            var series3 = chartType2.Series.Add("=" + countryName + "!$D$29:$D$" + chartrange, "=" + countryName + "!$A$29:$A$" + chartrange);
                            series3.Header = "Click Through Rate";

我需要做的最后一件事

感谢。

推荐答案

要添加辅助轴,需要执行以下操作:

To add a secondary axis the following needs to be done:

  // column - Clicks
                            var chartType3 = chart.PlotArea.ChartTypes.Add(eChartType.ColumnClustered);
                            var series2 = chartType3.Series.Add("=" + countryName + "!$C$29:$C$" + chartrange, "=" + countryName + "!$A$29:$A$" + chartrange);
                            series2.Header = "Clicks To Dealer";
                            chartType3.UseSecondaryAxis = true;

重要的是创建一个新的图表类型(charttype3),即使i和第一个图表,以便您可以使用chartType3.UseSecondaryAxis = true

it is important to make a new chart type (charttype3) even if i is the same as the first chart so that you can use chartType3.UseSecondaryAxis = true

这篇关于图表多类型和辅助Y轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆