Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

column chart and line chart combination...

Posted on 2014-08-03
2
Medium Priority
?
899 Views
Last Modified: 2014-08-04
The following code creates a column chart for the data in:

double[] yValues = { 15, 60, 12, 13 };  
string[] xValues = { "September", "October", "November", "December" };

Question: How can I add a 3rd series as line on the same column chart for data in: double[] yValues2 = { 30, 32, 30, 35 };

I suppose I have to change SeriesChartType.Column;  to something like SeriesChartType.Stacked??;  and somehow make the data in yValues2 avaialable to it.

I appreciate your time and effort in advance for participating in this question.

Thank you.
        double[] yValues = { 15, 60, 12, 13 };   //for column chart
        //double[] yValues2 = { 30, 32, 30, 35 };   //for line
        string[] xValues = { "September", "October", "November", "December" };

        Chart chart = new Chart();
        Series series = new Series("Default");
        series.ChartType = SeriesChartType.Column;
        series["PieLabelStyle"] = "Disabled";
        chart.Series.Add(series);

        ChartArea chartArea = new ChartArea();
        Axis yAxis = new Axis(chartArea, AxisName.Y);
        Axis xAxis = new Axis(chartArea, AxisName.X);

        chart.Series["Default"].Points.DataBindXY(xValues, yValues);
        chart.ChartAreas.Add(chartArea);

        chart.Width = new Unit(300, UnitType.Pixel);
        chart.Height = new Unit(200, UnitType.Pixel);
        string filename = "C:\\image\\Chart.png";
        chart.SaveImage(filename, ChartImageFormat.Png);

Open in new window

0
Comment
Question by:Mike Eghtebas
2 Comments
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 2000 total points
ID: 40238814
No, with stacked I think you can have multiple Y values but not different types of charts.

The thing is, if you look at the statement "series.ChartType = ..." (holding a single value), you start to suspect that you need to add a second series to the chart if you want another chart type for that data, using the same X values and the new Y values.

I think this is what you need:
            double[] yValues = { 15, 60, 12, 13 };   //for column chart
            double[] yValues2 = { 30, 32, 30, 35 };   //for line
            string[] xValues = { "September", "October", "November", "December" };

            Chart chart = new Chart();
            Series series = new Series("Default");
            series.ChartType = SeriesChartType.Column;
            series["PieLabelStyle"] = "Disabled";
            chart.Series.Add(series);

            Series series2 = new Series("Default2");
            series2.ChartType = SeriesChartType.Line;
            series2.Color = System.Drawing.Color.Red;
            series2.BorderWidth = 5; // this is actually the line width...
            chart.Series.Add(series2);

            ChartArea chartArea = new ChartArea();
            Axis yAxis = new Axis(chartArea, AxisName.Y);
            Axis xAxis = new Axis(chartArea, AxisName.X);

            chart.Series["Default"].Points.DataBindXY(xValues, yValues);
            chart.Series["Default2"].Points.DataBindXY(xValues, yValues2);
            chart.ChartAreas.Add(chartArea);

Open in new window

0
 
LVL 34

Author Closing Comment

by:Mike Eghtebas
ID: 40239615
Thank you very much.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month21 days, 6 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question