Search code examples
c#.netchartsdotnetcharting

Odd %Value in legend box of area chart (.NET charting)


I'm creating an area chart that contains multiple Series, each of them containing one Element for each calender week. Those Series will be displayed stacked in the area chart.

I also need a legend box that displays the name of each series in addition to it's total value. So I want to take the sum of all the elements in the Series and display it next to the name.

I therefore tried to style the label box like this

Chart.LegendBox.Template = "%Icon %Name %Value";

and indeed, it displays 3 parts. The Icon and Name are correct, but the value looks like this:

(38, 12.472)

It seems like it just displays the last Element's x and y value(calender week 38 is the end of my filter). As I said above, I'd like this to be the sum of all y values. Is there a way to

  • change the way %Value is generated or
  • add another string to the templates (like %Totalvalue) and modify it?

Solution

  • You can change the %Value item of a series by modifying the Series.LegendEntry:

    s.LegendEntry.Value = 42; //Change this to the number you want to be displayed in the legend