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.