Fine tune column chart c#

Posted on 2014-08-04
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.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

Question by:Mike Eghtebas
    LVL 35

    Accepted Solution

    Give these a try:
                // 1 don't show grid
                chartImage.ChartAreas[0].AxisX.MajorGrid.Enabled = false;
                chartImage.ChartAreas[0].AxisY.MajorGrid.Enabled = false;
                // 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;

    Open in new window

    LVL 33

    Author Comment

    by:Mike Eghtebas
    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?


    LVL 35

    Expert Comment

    by:Robert Schutt
    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

    LVL 33

    Author Comment

    by:Mike Eghtebas
    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).


    LVL 33

    Author Closing Comment

    by:Mike Eghtebas
    Thank you.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
    IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    733 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

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now