We help IT Professionals succeed at work.

Fine tune column chart asp.net c#

536 Views
Last Modified: 2014-08-04
There are 4 items numbered 1 through 4 on the attached image. I hope to be able to do them by revising the code below:

Question: Could you please review to see if all or some of them doable?

Thank you.
    protected void Page_Load(object sender, EventArgs e)
    {
            var chartImage = new Chart();
            chartImage.Width = 600;
            chartImage.Height = 400;

            //chartImage.Titles.Add("Sample Chart");
            chartImage.Series.Add("Decade");
           // chartImage.Legends.Add(chartImage.Series[0].Name); // optional, show legend

            // add data points
            object[] xValue = { "1970", "1980", "1990", "2000", "2010" };
            object[] yValues = { "9", "22", "52", "89", "123" };
            for (int x = 0; x < xValue.Length; x++) {
                chartImage.Series[0].Points.AddXY(xValue[x], yValues[x]);} // may need to cast to double, if "option strict"
 
            chartImage.ChartAreas.Add("chartArea0"); // always need to add this
            chartImage.ChartAreas[0].AxisX.Title = "Decade"; // optional, show axis x title
           // chartImage.ChartAreas[0].AxisY.Title = "Incidence"; // optional, show axis y title
            chartImage.ChartAreas[0].AxisX.LabelStyle.Angle = 90;
            chartImage.ImageStorageMode = ImageStorageMode.UseImageLocation; // avoid having to define http handler for now, simpler for quick testing
            this.Controls.Add(chartImage); // add to page for automatic rendering
        }

Open in new window

ColumnChart.png
Comment
Watch Question

Software Engineer
CERTIFIED EXPERT
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
Mike EghtebasDatabase and Application Developer

Author

Commented:
Hi Rober,

Thank you very much for the very good solution you gave to me. As shown on the attached image:

1. The border for ChartAreas[0] is also eliminated in removing the major axis. I tired to use the line below but it didn't work:
chartImage.ChartAreas[0].BorderColor = System.Drawing.Color.DeepPink;

2. Is it possible to remove the y-axis graduation as well?

Regards,

Mike
ColumnChart2.png
Robert SchuttSoftware Engineer
CERTIFIED EXPERT

Commented:
Try this:
1. Besides setting BorderColor, also set (not really sure why...):
chartImage.ChartAreas[0].BorderDashStyle = ChartDashStyle.Solid;

Open in new window

2. What you call graduation is called tick marks:
chartImage.ChartAreas[0].AxisY.MajorTickMark.Enabled = false;

Open in new window

Mike EghtebasDatabase and Application Developer

Author

Commented:
Thank you very much for the solution.

I have a follow up question if you have a couple of minutes (in your case probably couple of second because you seem to be very comfortable with the subject).

https://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_28490290.html

Regards,

Mike
Mike EghtebasDatabase and Application Developer

Author

Commented:
Thank you.

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