Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

modify chart c#

Posted on 2014-08-04
2
Medium Priority
?
474 Views
Last Modified: 2014-08-04
I have good solutions from Robert Schutt at:

http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_28489916.html

In my posts,I have used two different chart samples. Now I am having a bit trouble consolidating the solutions.

Question How can I consolidate solution 1 through 6 with the code below it?

Thank you.
            // 1 don't show grid*********************************************************
            chartImage.ChartAreas[0].AxisX.MajorGrid.Enabled = false;
           chartImage.ChartAreas[0].AxisY.MajorGrid.Enabled = false;
           chartImage.ChartAreas[0].BorderWidth = 1;

           // 2 remove y labels?********************************************************
            chartImage.ChartAreas[0].AxisY.LabelStyle.Enabled = false;

            // 3 show value*************************************************************
            chartImage.Series[0].IsValueShownAsLabel = true;
            chartImage.Series[0].LabelForeColor = System.Drawing.Color.Blue;

            // 4 rotate x labels**********************************************************
           chartImage.ChartAreas[0].AxisX.LabelStyle.Angle = 90;

           //5.remove tick marks and add border*************************************
           chartImage.ChartAreas[0].AxisY.MajorTickMark.Enabled = false;

           //6. add border************************************************************
           chartImage.ChartAreas[0].BorderDashStyle = ChartDashStyle.Solid;
           chartImage.ChartAreas[0].BorderColor = System.Drawing.Color.DeepPink;

The above solutions (1-6) to be included with:
       double[] yValues = { 15, 60, 12, 13 };   //for column chart
        double[] yValues2 = { 30, 32, 30, 0 };   //for line
        string[] xValues = { "September", "October", "November", "December" };

        Chart chart = new Chart();

        Series series = new Series("Default");
        series.ChartType = SeriesChartType.Column;
        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.Series["Default"].Color = System.Drawing.Color.Blue; // change default if you want to
        chart.Series["Default"].Points[0].Color = System.Drawing.Color.Red;
        chart.Series["Default"].Points[chart.Series["Default"].Points.Count - 1].Color = System.Drawing.Color.Orange;

        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: 40239728
Well the main thing would be that you can only set properties on the series and chartAreas after they have been created. In this case it's probably nicer to use the variables you create for that instead of the indexed properties of the Chart object. Question is if both series need to have a label shown which might overlap (see the comment in the code below). All in all it should be something like this:
            double[] yValues = { 15, 60, 12, 13 };   //for column chart
            double[] yValues2 = { 30, 32, 30, 0 };   //for line
            string[] xValues = { "September", "October", "November", "December" };

            Chart chart = new Chart();

            Series series = new Series("Default");
            series.ChartType = SeriesChartType.Column;
            chart.Series.Add(series);

            // 3 show value*************************************************************
            series.IsValueShownAsLabel = true;
            series.LabelForeColor = System.Drawing.Color.Blue;

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

            // also show value label for series2?
            //series2.IsValueShownAsLabel = true;
            //series2.LabelForeColor = System.Drawing.Color.Purple;

            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.Series["Default"].Color = System.Drawing.Color.Blue; // change default if you want to
            chart.Series["Default"].Points[0].Color = System.Drawing.Color.Red;
            chart.Series["Default"].Points[chart.Series["Default"].Points.Count - 1].Color = System.Drawing.Color.Orange;

            // 1 don't show grid*********************************************************
            chartArea.AxisX.MajorGrid.Enabled = false;
            chartArea.AxisY.MajorGrid.Enabled = false;
            chartArea.BorderWidth = 1;

            // 2 remove y labels?********************************************************
            chartArea.AxisY.LabelStyle.Enabled = false;

            // 4 rotate x labels**********************************************************
            chartArea.AxisX.LabelStyle.Angle = 90;

            //5.remove tick marks and add border*************************************
            chartArea.AxisY.MajorTickMark.Enabled = false;

            //6. add border************************************************************
            chartArea.BorderDashStyle = ChartDashStyle.Solid;
            chartArea.BorderColor = System.Drawing.Color.DeepPink;

            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
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 40239761
Thank you.

There is yet another question turning these charts to dynamic data source. If interested please see:
http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_28490316.html


Regards,

Mike
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

577 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