We help IT Professionals succeed at work.

modify chart c#

607 Views
Last Modified: 2014-08-04
I have good solutions from Robert Schutt at:

https://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

Comment
Watch Question

Software Engineer
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Mike EghtebasDatabase and Application Developer

Author

Commented:
Thank you.

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


Regards,

Mike

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.