Link to home
Start Free TrialLog in
Avatar of Mike Eghtebas
Mike EghtebasFlag for United States of America

asked on

modify chart c#

I have good solutions from Robert Schutt at:

https://www.experts-exchange.com/questions/28489916/Fine-tune-column-chart-asp-net-c.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

ASKER CERTIFIED SOLUTION
Avatar of Robert Schutt
Robert Schutt
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mike Eghtebas

ASKER

Thank you.

There is yet another question turning these charts to dynamic data source. If interested please see:
https://www.experts-exchange.com/questions/28490316/supplying-dynamic-data-to-a-chart-asp-net-c.html


Regards,

Mike