简体   繁体   中英

Winforms - How to get label in between of the x-axis datapoints

System.Web.UI.DataVisualization.Charting

System.Windows.Forms.DataVisualization.Charting

BarCharts - Current:

Bar Charts - Required:

or this:

Is it possible for me to get the label in between the x axis ticks?

Thanks!

Found the solution!

WinForms Chart control - Show labels between ticks

How to give custom labels to x axis of chart control?

1) Change the AxisX tick position.

chart1.ChartAreas[0].AxisX.MajorTickMark.IntervalOffset =
                        chart1.ChartAreas[0].AxisX.Interval / 2f;

2) Set up the Custom Label

int startOffset = 0;
int endOffset = 1;

for (int i = earliestHour; i <= latestHour; i++)
{
   CustomLabel label_chart = new CustomLabel(startOffset, endOffset, xAxis_Label,0, LabelMarkStyle.None);                       
   chart1.ChartAreas[0].AxisX.CustomLabels.Add(label_chart);
   startOffset+=1;
   endOffset+=1;
}

And... you get this!

image

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM