wxIshiko / wxCharts

A library to create charts in wxWidgets applications
https://www.wxishiko.com/wxCharts/
MIT License
131 stars 51 forks source link

the color of serie in legend are wrong #229

Closed rodingbao closed 1 month ago

rodingbao commented 1 month ago

image image image image

xleclercq commented 1 month ago

I'm currently fixing/improving the build system but will try to have a look at this soon.

xleclercq commented 1 month ago

I see you are using a custom color scheme. What method did you use to set the colors on the bar or column chart? Are you changing the wxChartsDefaultTheme or creating another theme entirely?

xleclercq commented 1 month ago

Actually, looking at your other bug report (https://github.com/wxIshiko/wxCharts/issues/228) it seems it's working for the line chart but that's weird because I think they use the same inputs. Are you doing anything different between the line chart and bar chart?

rodingbao commented 1 month ago

yes, they use the same inputs. no different between the line chart and bar chart. I changed the wxChartsDefaultTheme. I attached my code for reference.

wxChartsDatasetTheme *datasettheme = new wxChartsDatasetTheme();
if (chartType == B_CHART_VBAR)
  datasettheme->SetColumnChartDatasetOptions(
      wxColumnChartDatasetOptions(wxChartsPenOptions(color, 2), wxChartsBrushOptions(color)));
else if (chartType == B_CHART_HBAR)
  datasettheme->SetBarChartDatasetOptions(
      wxBarChartDatasetOptions(wxChartsPenOptions(color, 2), wxChartsBrushOptions(color)));
else if (chartType == B_CHART_VSBAR)
  datasettheme->SetStackedColumnChartDatasetOptions(
      wxStackedColumnChartDatasetOptions(wxChartsPenOptions(color, 2), wxChartsBrushOptions(color)));
else if (chartType == B_CHART_HSBAR)
  datasettheme->SetStackedBarChartDatasetOptions(
      wxStackedBarChartDatasetOptions(wxChartsPenOptions(color, 2), wxChartsBrushOptions(color)));
else
  datasettheme->SetLineChartDatasetOptions(wxLineChartDatasetOptions(color, color, wxTransparentColor));
wxChartsDefaultTheme->SetDatasetTheme(wxChartsDatasetId::CreateImplicitId(i),
                                      wxSharedPtr<wxChartsDatasetTheme>(datasettheme));
rodingbao commented 1 month ago

I add following code, the issue was solved .it seems that the legend used the color from line theme,

 wxChartsDefaultTheme->GetDatasetTheme(wxChartsDatasetId::CreateImplicitId(i))
        ->SetLineChartDatasetOptions(wxLineChartDatasetOptions(color, color, color));