我有一堆产品图表,总共35个.他们扩大了X轴.该图表很好,但只有5个产品名称显示,我需要它们全部显示.我已将MinorTickMark设为true,因此所有刻度线都会显示,但我如何才能看到它们各自的标签?
我无法将图像发布,所以这里是aspx标记和背后的代码..aspx标记;
<asp:Chart ID="MonthinYearchart" Width="350px" Height="420px" runat="server">
<Series>
<asp:Series ChartType="Bar" ChartArea="MainChartArea" Name="PnL">
</asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea Name="MainChartArea">
</asp:ChartArea>
</ChartAreas>
</asp:Chart>
Run Code Online (Sandbox Code Playgroud)
以下是将示例数据放入图表的代码.
Private Sub AllCommodforMonthChart()
Dim cht As Chart = MonthinYearchart
'create the arraylist of data
'this is hardcoded to get chart to work, you will have to
'set up the code to retrieve it from database
Dim list As List(Of String) = GetList("Futures Data")
Const val As Integer = 65
'create all the data points
For i As Integer = 0 To list.Count - 1
cht.Series("PnL").Points.AddXY(list(i), val * i)
Next
cht.Series("PnL").ChartType = SeriesChartType.Bar
cht.ChartAreas("MainChartArea").AxisX.MinorTickMark.Enabled = True
End Sub
Run Code Online (Sandbox Code Playgroud)
答案就在 Axis LabelStyles 中。下面的代码将格式化轴(X 或 Y),以便显示所有小刻度线,间隔为 1,并且将显示每个刻度线的所有标签。
cht.ChartAreas("MainChartArea").AxisX.MinorTickMark.Enabled = True
cht.ChartAreas("MainChartArea").AxisX.Interval = 1
cht.ChartAreas("MainChartArea").AxisX.IsLabelAutoFit = True
'cht.ChartAreas("MainChartArea").AxisX.LabelStyle.IsStaggered = True
cht.ChartAreas("MainChartArea").AxisX.LabelAutoFitStyle = LabelAutoFitStyles.DecreaseFont
Run Code Online (Sandbox Code Playgroud)
注意:如果您希望标签交错,请取消注释倒数第二行