在图例和图表中包含X轴标签

时间:2016-08-31 16:34:16

标签: c# asp.net

我试图显示一个饼图,其中X轴不仅显示在图例中,还显示在图表中的Y轴值。我以为我以前做过这个,但似乎无法回想起语法,也无法在任何地方找到它。这是我的代码,显示除了图表上的X轴以外的所有内容。

private void ChartData()
{
    ReportsChart.Palette = ChartColorPalette.BrightPastel;
    Collection<Legend> arg_2B_0 = ReportsChart.Legends;
    Legend legend = new Legend("Legend");
    legend.Docking = Docking.Right;
    arg_2B_0.Add(legend);
    ReportsChart.ChartAreas[0].AxisX.Interval = (1.0);
    ReportsChart.ChartAreas[0].AxisX.IsReversed = true;

    if (var1 == "CompanyChart")
    {
        ReportsChart.Series.Add("Report1");
        ReportsChart.Series[0].Points.DataBind(SqlDS1.Select(DataSourceSelectArguments.Empty), "Company", "Orders", "");
        ReportsChart.Series[0].IsXValueIndexed = true;
        ChartType("pie")
    }
}

private void ChartType(string type)
{
    if (type == "pie")
    {
        foreach (Series current in ReportsChart.Series)
        {
            current.ChartType = SeriesChartType.Pie;
            current.IsXValueIndexed = true;
            current.IsValueShownAsLabel = true;
        }
    }
}

}

1 个答案:

答案 0 :(得分:1)

Got it...

Added the following to show both X and Y labels on the chart:

 ReportsChart.Series[0].Label = "#VALX - #VALY";

And added the following to fix the legend so it does't show both values:

 ReportsChart.Series[0].LegendText = "#VALX";

For anyone that comes across this post, you can optionally format the axis in the same statement such as the following if it was currency:

 ReportsChart.Series[0].Label = "#VALX - #VALY{C}";