简体   繁体   中英

Include X-Axis Label in Legend and on Chart

I'm trying to display a pie chart with the X-Axis being displayed not only in the legend but also in the chart by the Y-Axis value. I thought I'd done this before but can't seem to recall the syntax nor find it online anywhere. Here's my code showing everything except the X-Axis on the chart.

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;
        }
    }
}

}

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}";

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