1
votes

I have just started using DevExpress Charting Components and I am trying out a Pie Chart.

It works fine, but I have a problem and I can't find the answer anywhere even though it's probably quite simple.

The Legend shows the percentages but I need it to show the "ArgumentDataMember" otherwise the legend is not really helpful.

This is the short code:

    Series series1 = new Series("Series1", ViewType.Pie3D);

    chartControl.Series.Add(series1);

    series1.DataSource = dt;
    series1.ArgumentScaleType = ScaleType.Qualitative;
    series1.ArgumentDataMember = "CategoryName";
    series1.ValueScaleType = ScaleType.Numerical;
    series1.ValueDataMembers.AddRange(new string[] { "Products" });
    series1.LegendText = series1.ArgumentDataMember;
    chartControl.Legend.Visible = true;

Obviously series1.LegendText = series1.ArgumentDataMember; didn't work.

Does anybody know how to use the argument (data name) as legend text instead of the values?

3

3 Answers

1
votes
 Series series1 = new Series("Series1", ViewType.Pie3D);

    chartControl.Series.Add(series1);

    series1.DataSource = dt;
    series1.ArgumentScaleType = ScaleType.Qualitative;
    series1.ArgumentDataMember = "CategoryName";
    series1.ValueScaleType = ScaleType.Numerical;
    series1.ValueDataMembers.AddRange(new string[] { "Products" });
   // series1.LegendText = series1.ArgumentDataMember;
   series1.PointOptions.PointView = PointView.Argument; //this is code that you want
  //if you only legend box change
  series1.LegendPointOptions.PointView = PointView.Argument;
    chartControl.Legend.Visible = true;
1
votes

You can use with LegendPointOptions with following code:

Series series1 = new Series("Series1", ViewType.Pie3D);

chartControl.Series.Add(series1);

series1.DataSource = dt;
series1.ArgumentScaleType = ScaleType.Qualitative;
series1.ArgumentDataMember = "CategoryName";
series1.ValueScaleType = ScaleType.Numerical;
series1.ValueDataMembers.AddRange(new string[] { "Products" });
series1.LegendText = series1.ArgumentDataMember;

series1.LegendPointOptions.Pattern = string.Concat("{V}");//or string.Concat("{A}") or string.Concat("{A}:{V}")

chartControl.Legend.Visible = true;
0
votes

You can set a property as false.

CType(series.PointOptions, PiePointOptions).PercentOptions.ValueAsPercent = False

Vb.NET Sample.

For Each series As Series In ChartControl1.Series
     If series.PointOptions.GetType = GetType(PiePointOptions) Then
          CType(series.PointOptions, PiePointOptions).PercentOptions.ValueAsPercent = False
          series.ShowInLegend = True
     End If
     series.PointOptions.ValueNumericOptions.Format = NumericFormat.Number
     series.PointOptions.ValueNumericOptions.Precision = 1
Next