MS chart-Sets the X-axis label according to the maximum minimum time of the database.

Source: Internet
Author: User

Core code:

Chart1.chartareas[0]. Axisx.interval = (front_max-front_min). DAYS/2; Chart1.chartareas[0]. Axisx.minimum = Front_min.tooadate (); Chart1.chartareas[0]. Axisx.maximum = Front_max.tooadate ();

Effect: Minimum database value: 2015-01-12, the maximum value is 2015-05-13, the middle shows a 2015-03-13, only 3 labels are displayed, if 4 lable is divided by 3. One of 4, 3 intervals.

Before because of the following line of code, the label date displays the start date, but extends back and forth for a period of time, the study has not known how to display the starting date.

Chart1.chartareas[0]. Axisx.intervaltype = System.Web.UI.DataVisualization.Charting.DateTimeIntervalType.Days

Delete this line of code, or change to the following, the default is this:

Chart1.chartareas[0]. Axisx.intervaltype = System.Web.UI.DataVisualization.Charting.DateTimeIntervalType.Auto;

Because the ChartType was previously set to date format.

Chart. Series[seriesname]. ChartType = Chartvaluetype.date

  

Add a modified version of the date range, date interval valid value check:

Try        {            chart1.chartareas[0]. Axisx.minimum = Front_min.adddays (-2). ToOADate ();            Chart1.chartareas[0]. Axisx.maximum = Front_max.adddays (2). ToOADate ();            Double days = (double) ((TimeSpan) (Front_max.adddays (2)-Front_min.adddays (-2))). Days;            Double labels = 2.0;            Check if the number of days was bigger than labels            if (Days > Labels)            {                //calculate the interval                dou ble interval = days/labels;                Chart1.chartareas[0]. Axisx.interval = Interval;            }            else            {                //Set the interval of 1 day                Chart1.chartareas[0]. Axisx.interval = 1;            }        }        Catch         {            //prevent null data         }

  

 

  

MS chart-Sets the X-axis label according to the maximum minimum time of the database.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.