Add a legend to wxMath2DPlot
Need help for adding a legend to wxMath2DPlot.
Many thanks,
Well, this type of chart hasn't associate with some string value and I'm not sure that it needed. So for now you can use code below:
wxVector<wxString> labels;//create vector for storing legend value
labels.push_back("first");//add as many string as many dataset was added to chartData
wxChartLegendData legendData;//create legend data
for(std::size_t i = 0; i<chartData.GetDatasets().size();i++)
{
//append pair (color,text) to legend
legendData.Append(
wxChartLegendItem(chartData.GetDatasets()[i]->GetLineColor(),
labels[i]));
}
wxChartLegendCtrl* legendCtrl = new wxChartLegendCtrl(panel, wxID_ANY, legendData,
wxDefaultPosition, wxDefaultSize, wxBORDER_NONE);
panelSizer->Add(legendCtrl, 1, wxEXPAND);//add to sizer
Thanks for the code.
It is working but I have some troubles to control the size of the legend chart. It seems that when associated to the same panel, the panel is splitted into two part of the same size, one part for the wxMath2Dplot chart and the second blank part contain only the legend chart as you can see below. I failed to locate it on the top of the wxMath2Dplot but this is may be due to my limited knowledge of wxwidgets.
Thanks for your help.

I failed to locate it on the top of the wxMath2Dplot but this is may be due to my limited knowledge of wxwidgets.
Usually and in the example too, controls are stored in sizers so you can choose their location by order of addition into sizer and by special arguments in method Add.
In your case:
panelSizer->Add(legendCtrl, 0, wxEXPAND);
panelSizer->Add(math2dPlotCtrl, 1, wxEXPAND);
For more information read the documentation and tutorials - Layout management in wxWidgets and Sizers.
Thanks. Very helpful indeed.
Worked but I prefered this one:
legendSizer->Add(legendCtrl,0,wxEXPAND); panelSizer->Add(math2dPlotCtrl, 1, wxEXPAND); panelSizer->Add(legendSizer, 0, wxEXPAND);

Still trying to introduce X and Y label.
Many thanks,