1
votes

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?

EDIT: 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

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";

The final thing that i need to do is add a secondary Y Axis - any help with that would be appreciated!

Thanks.

1

1 Answers

0
votes

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;

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