wxIshiko / wxCharts

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

how to define the color of legend of column chart? #212

Closed rodingbao closed 10 months ago

rodingbao commented 10 months ago

is there anyone know that how to define the color of legend of column chart?

Kvaz1r commented 10 months ago

Not sure if it's possible (long time didn't use the lib) but guess you can set color in wxChartFontOptions for "x" axis.

rodingbao commented 10 months ago

I try to add dataset and re-set the pen color with following code, but error occured as belowing. pls comments.

C:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ../build-Release/family/main.cpp.o:main.cpp:(.rdata$.refptr.wxChartsDefaultTheme[.refptr.wxChartsDefaultTheme]+0x0): undefined reference to `wxChartsDefaultTheme'

my code: wxChartsCategoricalData::ptr chartData = wxChartsCategoricalData::make_shared(labels);

// add dataset
wxVector<double> t_points;
for (size_t i = 0; i < points.size(); i++) {
  t_points.assign(points[i].begin(), points[i].end());
  wxChartsDoubleDataset::ptr dataset( new wxChartsDoubleDataset(seriesName[i], t_points));
  chartData->AddDataset(dataset);

  // define pen color
  wxChartsDatasetTheme *datasetTheme = new wxChartsDatasetTheme();
  datasetTheme->SetColumnChartDatasetOptions(wxColumnChartDatasetOptions(
      wxChartsPenOptions(wxColour(COLOR[i]), 2),
      wxChartsBrushOptions(wxColour(COLOR[i]))));
  wxChartsDefaultTheme->SetDatasetTheme(
      wxChartsDatasetId::CreateImplicitId(i),
      wxSharedPtr<wxChartsDatasetTheme>(datasetTheme));
}

for (int i = 0; i < points.size(); i++) //nDatasets - amount of datasets { auto color = wxChartsDefaultTheme->GetDatasetTheme(wxChartsDatasetId::CreateImplicitId(i))->GetStackedColumnChartDatasetOptions()->GetBrushOptions().GetColor(); wxChartsDefaultTheme->GetDatasetTheme(wxChartsDatasetId::CreateImplicitId(i))->SetLineChartDatasetOptions( wxLineChartDatasetOptions( color, color, color ) ); }