SetDataLabel not working

According to the documentation for SetDataLabel:


//     Changes the labels for the chart. You should always get the values with FlexCel.Core.ExcelChart.GetDataLabels(),
//     modify them, and change them back with this method.

However, when I do the following, the chart title is not modified.

     // in : ExcelChart chart;

     TDataLabel[] labels = chart.GetDataLabels();
     labels[0].LabelValues[0] = "Foobar";
     chart.SetDataLabels(labels);

When debugging in Visual Studio I see that it is the correct value being changed. However, when I export to PDF the chart title is not changed.

Thanks in advance for any feedback

Hi,

Sadly indeed SetDataLabel does not work, or what is worse, it works but it is useless.
Currently FlexCel doesn't support setting chart labels.

If I might expand, the story goes like this:  When we added chart support in v4.0, we planned for the TXlsChart object to behave like all other objects in FlexCel.
In FlexCel objects are loosely coupled, that means that differently from for example OLE Automation (or almost any other API out there which copy OLE Automation), a range in FlexCel is just a struct with 4 coordinates (Left, right, top and bottom). In the OLE automation model, a range keeps a reference to the worksheet it is in (which keeps a reference to the workbook, and well you get the idea).

The advantage in a loosely coupled model is that objects are much simpler and isolated (you don't have those pointers going everywhere and a range doesn't have to know about sheets, it is all top-down). But OLE Automation does have a nice feature that people normally miss: You can change the value in the range, and it changes in the sheet. (because the range is linked to a sheet). In FlexCel, you need to do:

object = xls.GetObject();
modify(object); //the object you get here doesn't know anything about xls, so modifying it won't modify xls.
xls.SetObject(object); //now you modify xls.

While in OLE Automation you can just write
Modify(xls.GetObject);

Now, why I am telling you all of this?  Because as said, XlsChart was supposed to be a normal FlexCel object, so in order to modify the chart, you would have to do:
Chart = Xls.Getchart();
Chart.SetLabel(...);
Xls.SetChart(Chart);

but, there is no SetChart in Xls, so while SetLabel does change the label in the Chart object, Xls doesn't know it is changed. That's why I said it works, but it doesn't do anything useful (because there is no "SetChart")

This is what was planned at 4.0 timeline: SetChart and GetChart methods, and methods like "SetLabel" that would modify the chart object itself, but would need to be applied with SetChart to modify the xls file. As we hadn't time in 4.0 to release a SetChart method, we released GetChart (Which we needed for chart rendering) and left SetChart for the future.

After that, 2 things happened:
1) We realized that having a Chart object behave like all the other objects wasn't a good idea, it is a very big object, so having it as a standalone object would have very bad performance as it would have to be copied back and forth.

2) Microsoft released xlsx and we had to postpone all plans for everything else to concentrate in supporting xlsx.

About 1), we have been switching the methods in TXlsChart to directly modify the xls file, not only the chart. That's why you can do a SetSeries and it indeed modifies the file. But we were constrained by time because of 2), and we couldn't dedicate too much time to it, all of this time we have been chasing xlsx (which meant completely rewriting FlexCel). So SetDataLabels didn't made it.

Our plans right now are to finish what is left of xlsx support (luckily it is just a couple of things, coming probably in 5.8 and 5.9) and then 6.0 will be focused in charts:  Rendering xlsx charts and also support for modifying them (be them xls or xlsx).

So that's the story. I will try to see if SetDataLabels can be made to modify the xls file directly in an update before 6.0, but I can't guarantee it, we 've tried it before and I remember there were a lot of snakes there. But I will give it another try, and if we can get it in a reasonable amount of time, we will add it before 6.0 is released.

Regards,
   Adrian.

Thank you for your feedback Adrian and for the extended explanation.


I do understand the issues here. However, it would be most appreciated if this could be fixed, since we generate charts based on different measurement data that also have different names. Getting a descriptive name instead of a generic one for the different charts would improve the output and "feel" of the program a lot.

If you do get around modifying Flexcel for this to be supported, do let me know.

Thanks in advance

I've flagged your email so I don't forget it, I will try to add this in the following weekends, and if it is feasible (that is, it can be added without a significant rewrite) I will notify you.


Regards,
   Adrian.