在图表控件X轴上显示所有数值

9
我有一个包含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>

这是将样本数据放入图表的代码后台。
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

@dinotom 你可以回答自己的问题。 - Drake
间隔=1解决了我的问题。 - Yasser Sobhdel
2个回答

2

图表控件非常有限,如果您想自定义它,最好创建自己的图表,通过生成图像:

查看链接


0
答案在于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

注意:如果您想要标签错开,请取消注释倒数第二行。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接