如何在图表上错过几个月 [英] How do I get missing months on graph
问题描述
大家好
我很难在图表上显示所有月份
图表显示12个月,但X轴只显示每隔一个月
如何在X轴上显示所有月份名称?
提前谢谢
我的尝试:
我已经尝试调整图表的大小,并希望它适合所有内容,但它没有。
它是图表中的设置属性还是用代码完成的东西?
chart1.Size = new Size(1200,500);
chart1。高度= 450;
chart1.Titles.Add(占用);
chartArea1.Position.Height = 80;
Hi All
I am having difficulty in displaying all the months on a graph
The graph displays 12 months but the X Axis only shows every other month
How do i get that all month names display on the X Axis?
Thank you in advance
What I have tried:
I have tried resizing the chart and was hoping it would then fit everything in but it does not.
it is a setting within the chart properties or is it something that can be done with code?
chart1.Size = new Size(1200, 500);
chart1.Height = 450;
chart1.Titles.Add("Occupancy");
chartArea1.Position.Height = 80;
推荐答案
试试这个:
Try this:
public class Data
{
public DateTime Date { get; set; }
public int Value { get; set; }
}
...
List<Data> data = new List<Data>();
for (int mon = 1; mon < 13; mon++)
{
data.Add(new Data() { Date = new DateTime(2018, mon, 1), Value = mon });
}
chart1.DataSource = data;
chart1.Series[0].XValueMember = "Date";
chart1.Series[0].YValueMembers = "Value";
chart1.ChartAreas[0].AxisX.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Months;
chart1.ChartAreas[0].AxisX.LabelStyle.Format = "MMM";
chart1.ChartAreas[0].AxisX.IntervalAutoMode = System.Windows.Forms.DataVisualization.Charting.IntervalAutoMode.VariableCount;
chart1.ChartAreas[0].AxisX.Interval = 1;
chart1.DataBind();
这篇关于如何在图表上错过几个月的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!