wxIshiko / wxCharts

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

Stacked Column Chart redraws first chart #167

Open gismowdd opened 4 years ago

gismowdd commented 4 years ago

I've got 4 wxRadioButtonBoxes that control which of 67 tables get charted. When a change in selection in any of the 4 wxRadioButtonBoxes occurs, the function ChangeGraph() is called that selects which of the 67 tables gets charted. This all works well, the problem is that whenever I move the cursor over the StackedColumnChartCtrl it redraws the first chart that was drawn disregarding whatever chart was being displayed.

`void AcornFrame::ChangeGraph() { int i,j,boxcode,nrows,ncols; int intyear = RadioBoxYear->GetSelection(); int intspecies = RadioBoxSpecies->GetSelection(); int intmetric = RadioBoxMetrics->GetSelection(); int intorigin = RadioBoxOrigin->GetSelection(); double **graphthis;

  if (intyear==0) boxcode=(intyear+1)*1000+intspecies*100+intmetric*10;
  else if (intyear==1) boxcode=(intyear+1)*1000+intspecies*100;
  else boxcode=(intyear+1)*1000+intspecies*100+intmetric*10+intorigin;
  if (intyear<2)ncols=25;else ncols=11;
  if (intspecies==0) nrows=13;
  else if(intspecies==1)nrows=36;
  else (nrows=6);

   graphthis = get_matrix_space(38,26);

wxWindow* ChartWindow = new wxWindow(Panel5,wxID_ANY,wxDefaultPosition, wxSize(1312,800));

for (i = 0;i <=nrows;++i)
{
    for(j=1;j<ncols;++j)
    {

if(boxcode== 1000 ) graphthis[i][j]= idbhtable[i][j] ; else if(boxcode== 1010 ) graphthis[i][j]= iBAtable[i][j] ; else if(boxcode== 1020 ) graphthis[i][j]= iSTKtable[i][j] ; else if(boxcode== 1100 ) graphthis[i][j]= idbhspeciestable[i][j] ; . , , } } CREATE LEGEND AND CHART DATA FROM graphthis . . .

wxChartsLegendData legendData(reverseChartdata->GetDatasets());
wxChartsLegendCtrl* legendCtrl = new wxChartsLegendCtrl(ChartWindow, wxID_ANY, legendData,wxPoint(991,30),wxSize(130,300), wxSIMPLE_BORDER);

// Create the bar chart widget

wxStackedColumnChartCtrl* stackedColumnChartCtrl = new wxStackedColumnChartCtrl(ChartWindow,
wxID_ANY, chartData, wxPoint(180,30),wxSize(800,520));

} `

Kvaz1r commented 4 years ago

Hmm, it's not so easy say something specific without reproducible sample. Does the behaviour will the same if charts replace with wxPanel?

gismowdd commented 4 years ago

Hi Kvaz1r , so it behaves like there is some sort of redraw event that occurs as soon as the cursor touches the stackedColumnChartCtrl. I don't think it's anything I added, I think it must be part of a default option. Possibly when the stackedColumnChartCtrl receives focus. I'm attaching my entire code so you can see what I've done.

`

void AcornFrame::ChangeGraph() { int i,j,boxcode,nrows,ncols; int intyear = RadioBoxYear->GetSelection(); int intspecies = RadioBoxSpecies->GetSelection(); int intmetric = RadioBoxMetrics->GetSelection(); int intorigin = RadioBoxOrigin->GetSelection(); double **graphthis;

  if (intyear==0) boxcode=(intyear+1)*1000+intspecies*100+intmetric*10;
  else if (intyear==1) boxcode=(intyear+1)*1000+intspecies*100;
  else boxcode=(intyear+1)*1000+intspecies*100+intmetric*10+intorigin;
  if (intyear<2)ncols=25;else ncols=11;
  if (intspecies==0) nrows=13;
  else if(intspecies==1)nrows=36;
  else (nrows=6);

   graphthis = get_matrix_space(38,26);

wxWindow* ChartWindow = new wxWindow(Panel5,wxID_ANY,wxDefaultPosition, wxSize(1312,800));

for (i = 0;i <=nrows;++i)
{
    for(j=1;j<ncols;++j)
    {

if(boxcode== 1000 ) graphthis[i][j]= idbhtable[i][j] ; else if(boxcode== 1010 ) graphthis[i][j]= iBAtable[i][j] ; else if(boxcode== 1020 ) graphthis[i][j]= iSTKtable[i][j] ; else if(boxcode== 1100 ) graphthis[i][j]= idbhspeciestable[i][j] ; else if(boxcode== 1110 ) graphthis[i][j]= iBAspeciestable[i][j] ; else if(boxcode== 1120 ) graphthis[i][j]= iSTKspeciestable[i][j] ; else if(boxcode== 1200 ) graphthis[i][j]= idbhclasstable[i][j] ; else if(boxcode== 1210 ) graphthis[i][j]= iBAclasstable[i][j] ; else if(boxcode== 1220 ) graphthis[i][j]= iSTKclasstable[i][j] ; else if(boxcode== 2000 ) graphthis[i][j]= height5table[i][j] ; else if(boxcode== 2100 ) graphthis[i][j]= height5speciestable[i][j] ; else if(boxcode== 2200 ) graphthis[i][j]= height5classtable[i][j] ; else if(boxcode== 3000 ) graphthis[i][j]= stumpdbh10table[i][j] ; else if(boxcode== 3001 ) graphthis[i][j]= Preprodbh10table[i][j] ; else if(boxcode== 3002 ) graphthis[i][j]= stumpdbh10table[i][j]+Preprodbh10table[i][j] ; else if(boxcode== 3010 ) graphthis[i][j]= stumpBA10table[i][j] ; else if(boxcode== 3011 ) graphthis[i][j]= reproBA10table[i][j] ; else if(boxcode== 3012 ) graphthis[i][j]= stumpBA10table[i][j]+reproBA10table[i][j] ; else if(boxcode== 3020 ) graphthis[i][j]= stumpSTK10table[i][j] ; else if(boxcode== 3021 ) graphthis[i][j]= reproSTK10table[i][j] ; else if(boxcode== 3022 ) graphthis[i][j]= stumpSTK10table[i][j]+reproBA10table[i][j] ; else if(boxcode== 3100 ) graphthis[i][j]= stumpdbh10speciestable[i][j] ; else if(boxcode== 3101 ) graphthis[i][j]= Preprodbh10speciestable[i][j] ; else if(boxcode== 3102 ) graphthis[i][j]= stumpdbh10speciestable[i][j]+Preprodbh10speciestable[i][j] ; else if(boxcode== 3110 ) graphthis[i][j]= stumpBA10speciestable[i][j] ; else if(boxcode== 3111 ) graphthis[i][j]= reproBA10speciestable[i][j] ; else if(boxcode== 3112 ) graphthis[i][j]= stumpBA10speciestable[i][j]+reproBA10speciestable[i][j] ; else if(boxcode== 3120 ) graphthis[i][j]= stumpSTK10speciestable[i][j] ; else if(boxcode== 3121 ) graphthis[i][j]= reproSTK10speciestable[i][j] ; else if(boxcode== 3122 ) graphthis[i][j]= stumpSTK10speciestable[i][j]+reproBA10speciestable[i][j] ; else if(boxcode== 3200 ) graphthis[i][j]= stumpdbh10classtable[i][j] ; else if(boxcode== 3201 ) graphthis[i][j]= reprodbh10classtable[i][j] ; else if(boxcode== 3202 ) graphthis[i][j]= stumpdbh10classtable[i][j]+reprodbh10classtable[i][j] ; else if(boxcode== 3210 ) graphthis[i][j]= stumpBA10classtable[i][j] ; else if(boxcode== 3211 ) graphthis[i][j]= reproBA10classtable[i][j] ; else if(boxcode== 3212 ) graphthis[i][j]= stumpBA10classtable[i][j]+reproBA10classtable[i][j] ; else if(boxcode== 3220 ) graphthis[i][j]= stumpSTK10classtable[i][j] ; else if(boxcode== 3221 ) graphthis[i][j]= reproSTK10classtable[i][j] ; else if(boxcode== 3222 ) graphthis[i][j]= stumpSTK10classtable[i][j]+reproBA10classtable[i][j] ; else if(boxcode== 4000 ) graphthis[i][j]= stumpdbh21table[i][j] ; else if(boxcode== 4001 ) graphthis[i][j]= reprodbh21table[i][j] ; else if(boxcode== 4002 ) graphthis[i][j]= stumpdbh21table[i][j]+reprodbh21table[i][j] ; else if(boxcode== 4010 ) graphthis[i][j]= stumpBA21table[i][j] ; else if(boxcode== 4011 ) graphthis[i][j]= reproBA21table[i][j] ; else if(boxcode== 4012 ) graphthis[i][j]= stumpBA21table[i][j]+reproBA21table[i][j] ; else if(boxcode== 4020 ) graphthis[i][j]= stumpSTK21table[i][j] ; else if(boxcode== 4021 ) graphthis[i][j]= reproSTK21table[i][j] ; else if(boxcode== 4022 ) graphthis[i][j]= stumpSTK21table[i][j]+reproBA21table[i][j] ; else if(boxcode== 4100 ) graphthis[i][j]= stumpdbh21speciestable[i][j] ; else if(boxcode== 4101 ) graphthis[i][j]= reprodbh21speciestable[i][j] ; else if(boxcode== 4102 ) graphthis[i][j]= stumpdbh21speciestable[i][j]+reprodbh21speciestable[i][j] ; else if(boxcode== 4110 ) graphthis[i][j]= stumpBA21speciestable[i][j] ; else if(boxcode== 4111 ) graphthis[i][j]= reproBA21speciestable[i][j] ; else if(boxcode== 4112 ) graphthis[i][j]= stumpBA21speciestable[i][j]+reproBA21speciestable[i][j] ; else if(boxcode== 4120 ) graphthis[i][j]= stumpSTK21speciestable[i][j] ; else if(boxcode== 4121 ) graphthis[i][j]= reproSTK21speciestable[i][j] ; else if(boxcode== 4122 ) graphthis[i][j]= stumpSTK21speciestable[i][j]+reproBA21speciestable[i][j] ; else if(boxcode== 4200 ) graphthis[i][j]= stumpdbh21classtable[i][j] ; else if(boxcode== 4201 ) graphthis[i][j]= reprodbh21classtable[i][j] ; else if(boxcode== 4202 ) graphthis[i][j]= stumpdbh21classtable[i][j]+reprodbh21classtable[i][j] ; else if(boxcode== 4210 ) graphthis[i][j]= stumpBA21classtable[i][j] ; else if(boxcode== 4211 ) graphthis[i][j]= reproBA21classtable[i][j] ; else if(boxcode== 4212 ) graphthis[i][j]= stumpBA21classtable[i][j]+reproBA21classtable[i][j] ; else if(boxcode== 4220 ) graphthis[i][j]= stumpSTK21classtable[i][j] ; else if(boxcode== 4221 ) graphthis[i][j]= reproSTK21classtable[i][j] ; else if(boxcode== 4222 ) graphthis[i][j]= stumpSTK21classtable[i][j]+reproBA21classtable[i][j] ;

    }

}

double testno1;
double testno2;
double testno3;
double testno4;
double testno5;
double testno6;
double testno7;
double testno8;
double testno9;
double testno10;
double testno11;
double testno12;
double testno13;

wxString templabel;
wxVector<wxString> labels;
 for(j=1;j<ncols;++j)
{
templabel =wxString::Format(wxT("%4.1lf"), graphthis[0][j]);
labels.push_back(templabel);
}

//wxChartsCategoricalData::ptr chartData=(new wxChartsDoubleDataset("Dataset 0", points0));
 wxChartsCategoricalData::ptr chartData = wxChartsCategoricalData::make_shared(labels);
 wxChartsCategoricalData::ptr reverseChartdata = wxChartsCategoricalData::make_shared(labels);

// Add the first dataset wxVector points1; for(j=1;j<ncols;++j) {

testno1=graphthis[1][j];
points1.push_back(testno1);
}
 wxChartsDoubleDataset::ptr dataset1(new wxChartsDoubleDataset("Mixed Species", points1));
chartData->AddDataset(dataset1);

// Add the second dataset
wxVector<wxDouble> points2;
for(j=1;j<ncols;++j)
{

testno2=graphthis[2][j];
points2.push_back(testno2);
}
wxChartsDoubleDataset::ptr dataset2(new wxChartsDoubleDataset("Dogwood", points2));
chartData->AddDataset(dataset2);

 // Add the first dataset
wxVector<wxDouble> points3;
for(j=1;j<ncols;++j)
{

testno3=graphthis[3][j];
points3.push_back(testno3);
}
wxChartsDoubleDataset::ptr dataset3(new wxChartsDoubleDataset("Sassafras", points3));
chartData->AddDataset(dataset3);

// Add the second dataset
wxVector<wxDouble> points4;
for(j=1;j<ncols;++j)
{

testno4=graphthis[4][j];
points4.push_back(testno4);
}
wxChartsDoubleDataset::ptr dataset4(new wxChartsDoubleDataset("Hickory", points4));
chartData->AddDataset(dataset4);

// Add the first dataset
wxVector<wxDouble> points5;
for(j=1;j<ncols;++j)
{

testno5=graphthis[5][j];
points5.push_back(testno5);
}
wxChartsDoubleDataset::ptr dataset5(new wxChartsDoubleDataset("Blackgum", points5));
chartData->AddDataset(dataset5);

// Add the second dataset wxVector points6; for(j=1;j<ncols;++j) {

testno6=graphthis[6][j];
points6.push_back(testno6);
}
wxChartsDoubleDataset::ptr dataset6(new wxChartsDoubleDataset("White Oak", points6));
chartData->AddDataset(dataset6);

// Add the third dataset
    wxVector<wxDouble> points7;
for(j=1;j<ncols;++j)
{

testno7=graphthis[7][j];
points7.push_back(testno7);
}
wxChartsDoubleDataset::ptr dataset7(new wxChartsDoubleDataset("Post Oak", points7));
chartData->AddDataset(dataset7);

// Add the fourth dataset
  wxVector<wxDouble> points8;
for(j=1;j<ncols;++j)
{

testno8=graphthis[8][j];
points8.push_back(testno8);
}
wxChartsDoubleDataset::ptr dataset8(new wxChartsDoubleDataset("Blackjack Oak", points8));
chartData->AddDataset(dataset8);

// Add the fifth dataset
wxVector<wxDouble> points9;
for(j=1;j<ncols;++j)
{
testno9=graphthis[9][j];
points9.push_back(testno9);
}
wxChartsDoubleDataset::ptr dataset9(new wxChartsDoubleDataset("Black Oak", points9));
chartData->AddDataset(dataset9);

// Add the fifth dataset
wxVector<wxDouble> points10;
for(j=1;j<ncols;++j)
{
testno10=graphthis[10][j];
points10.push_back(testno10);
}
wxChartsDoubleDataset::ptr dataset10(new wxChartsDoubleDataset("Scarlet Oak", points10));
chartData->AddDataset(dataset10);

    // Add the eleventh dataset
  wxVector<wxDouble> points11;
for(j=1;j<ncols;++j)
{

testno11=graphthis[11][j];
points11.push_back(testno11);
}
wxChartsDoubleDataset::ptr dataset11(new wxChartsDoubleDataset("S. Red Oak", points11));
chartData->AddDataset(dataset11);

// Add the twelveth dataset
wxVector<wxDouble> points12;
for(j=1;j<ncols;++j)
{
testno12=graphthis[12][j];
points12.push_back(testno12);
}
wxChartsDoubleDataset::ptr dataset12(new wxChartsDoubleDataset("N. Red Oak", points12));
chartData->AddDataset(dataset12);

// Add the thirteenth dataset
wxVector<wxDouble> points13;
for(j=1;j<ncols;++j)
{
testno13=graphthis[13][j];
points13.push_back(testno13);
}
wxChartsDoubleDataset::ptr dataset13(new wxChartsDoubleDataset("Other Oaks", points13));
chartData->AddDataset(dataset13);

reverseChartdata->AddDataset(dataset13);
reverseChartdata->AddDataset(dataset12);
reverseChartdata->AddDataset(dataset11);
reverseChartdata->AddDataset(dataset10);
reverseChartdata->AddDataset(dataset9);
reverseChartdata->AddDataset(dataset8);
reverseChartdata->AddDataset(dataset7);
reverseChartdata->AddDataset(dataset6);
reverseChartdata->AddDataset(dataset5);
reverseChartdata->AddDataset(dataset4);
reverseChartdata->AddDataset(dataset3);
reverseChartdata->AddDataset(dataset2);
reverseChartdata->AddDataset(dataset1);

// Create the legend widget

wxChartsLegendData legendData(reverseChartdata->GetDatasets());
wxChartsLegendCtrl* legendCtrl = new wxChartsLegendCtrl(ChartWindow, wxID_ANY, legendData,wxPoint(991,30),wxSize(130,300), wxSIMPLE_BORDER);

// Create the bar chart widget

wxStackedColumnChartCtrl* stackedColumnChartCtrl = new wxStackedColumnChartCtrl(ChartWindow,
wxID_ANY, chartData, wxPoint(180,30),wxSize(800,520));

}

void AcornFrame::OnRadioBoxYearSelect(wxCommandEvent& event) { ChangeGraph();

}

void AcornFrame::OnRadioBoxMetricsSelect(wxCommandEvent& event) { ChangeGraph();

}

void AcornFrame::OnRadioBoxSpeciesSelect(wxCommandEvent& event) { ChangeGraph();

}

void AcornFrame::OnRadioBoxOriginSelect(wxCommandEvent& event) { ChangeGraph();

}

`

Kvaz1r commented 4 years ago

I only see that you at every call ChangeGraph() add new control to ChartWindow as a child and never remove any control from there. You should replace old control with new one because only few charts have support of dynamic data and StackedColumnChart not one of them.

So just add stackedColumnChartCtrl and legendCtrl to fields of AcornFrame. And after updating value of pointer relayout frame.

gismowdd commented 4 years ago

i've written a simpler program that exihbits the same behavior. You can select one of three table to graph and press the run button, the table will display. if you repeat the process and select another it will display until you move the cursor over the chartctrl window then it changes to which ever you first displayed. newtestApp.h `#ifndef NEWTESTAPP_H

define NEWTESTAPP_H

include <wx/app.h>

class newtestApp : public wxApp { public: virtual bool OnInit(); };

endif // NEWTESTAPP_H

` newtestMain.h

`

ifndef NEWTESTMAIN_H

define NEWTESTMAIN_H

include <wx/charts/wxcharts.h>

//(*Headers(newtestFrame)

include <wx/button.h>

include <wx/frame.h>

include <wx/menu.h>

include <wx/panel.h>

include <wx/radiobox.h>

include <wx/statusbr.h>

//*)

class newtestFrame: public wxFrame { public:

    newtestFrame(wxWindow* parent,wxWindowID id = -1);
    virtual ~newtestFrame();
    double** get_matrix_space(int m, int n);

private:

    //(*Handlers(newtestFrame)
    void OnQuit(wxCommandEvent& event);
    void OnAbout(wxCommandEvent& event);
    void OnButton1Click(wxCommandEvent& event);
    //*)

    //(*Identifiers(newtestFrame)
    static const long ID_RADIOBOX1;
    static const long ID_BUTTON1;
    static const long ID_PANEL1;
    static const long idMenuQuit;
    static const long idMenuAbout;
    static const long ID_STATUSBAR1;
    //*)

    //(*Declarations(newtestFrame)
    wxButton* Button1;
    wxPanel* Panel1;
    wxRadioBox* RadioBox1;
    wxStatusBar* StatusBar1;
    //*)

    DECLARE_EVENT_TABLE()

};

endif // NEWTESTMAIN_H

` newtestApp.cpp

`#include "newtestApp.h"

//(*AppHeaders

include "newtestMain.h"

include <wx/image.h>

//*)

IMPLEMENT_APP(newtestApp);

bool newtestApp::OnInit() { //(AppInitialize bool wxsOK = true; wxInitAllImageHandlers(); if ( wxsOK ) { newtestFrame Frame = new newtestFrame(0); Frame->Show(); SetTopWindow(Frame); } //*) return wxsOK;

}`

newtestMain.cpp

`/***

include "newtestMain.h"

include <wx/msgdlg.h>

//(*InternalHeaders(newtestFrame)

include <wx/intl.h>

include <wx/string.h>

//*)

//helper functions enum wxbuildinfoformat { short_f, long_f };

wxString wxbuildinfo(wxbuildinfoformat format) { wxString wxbuild(wxVERSION_STRING);

if (format == long_f )
{

if defined(WXMSW)

    wxbuild << _T("-Windows");

elif defined(UNIX)

    wxbuild << _T("-Linux");

endif

if wxUSE_UNICODE

    wxbuild << _T("-Unicode build");

else

    wxbuild << _T("-ANSI build");

endif // wxUSE_UNICODE

}

return wxbuild;

}

//(IdInit(newtestFrame) const long newtestFrame::ID_RADIOBOX1 = wxNewId(); const long newtestFrame::ID_BUTTON1 = wxNewId(); const long newtestFrame::ID_PANEL1 = wxNewId(); const long newtestFrame::idMenuQuit = wxNewId(); const long newtestFrame::idMenuAbout = wxNewId(); const long newtestFrame::ID_STATUSBAR1 = wxNewId(); //)

BEGIN_EVENT_TABLE(newtestFrame,wxFrame) //(EventTable(newtestFrame) //) END_EVENT_TABLE()

newtestFrame::newtestFrame(wxWindow parent,wxWindowID id) { //(Initialize(newtestFrame) wxMenu Menu1; wxMenu Menu2; wxMenuBar MenuBar1; wxMenuItem MenuItem1; wxMenuItem* MenuItem2;

Create(parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, _T("id"));
SetClientSize(wxSize(1019,534));
Panel1 = new wxPanel(this, ID_PANEL1, wxPoint(168,232), wxDefaultSize, wxTAB_TRAVERSAL, _T("ID_PANEL1"));
wxString __wxRadioBoxChoices_1[3] =
{
    _("ONE"),
    _("TWO"),
    _("THREE")
};
RadioBox1 = new wxRadioBox(Panel1, ID_RADIOBOX1, _("Choose"), wxPoint(48,72), wxDefaultSize, 3, __wxRadioBoxChoices_1, 1, 0, wxDefaultValidator, _T("ID_RADIOBOX1"));
Button1 = new wxButton(Panel1, ID_BUTTON1, _("RUN"), wxPoint(48,192), wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON1"));
MenuBar1 = new wxMenuBar();
Menu1 = new wxMenu();
MenuItem1 = new wxMenuItem(Menu1, idMenuQuit, _("Quit\tAlt-F4"), _("Quit the application"), wxITEM_NORMAL);
Menu1->Append(MenuItem1);
MenuBar1->Append(Menu1, _("&File"));
Menu2 = new wxMenu();
MenuItem2 = new wxMenuItem(Menu2, idMenuAbout, _("About\tF1"), _("Show info about this application"), wxITEM_NORMAL);
Menu2->Append(MenuItem2);
MenuBar1->Append(Menu2, _("Help"));
SetMenuBar(MenuBar1);
StatusBar1 = new wxStatusBar(this, ID_STATUSBAR1, 0, _T("ID_STATUSBAR1"));
int __wxStatusBarWidths_1[1] = { -1 };
int __wxStatusBarStyles_1[1] = { wxSB_NORMAL };
StatusBar1->SetFieldsCount(1,__wxStatusBarWidths_1);
StatusBar1->SetStatusStyles(1,__wxStatusBarStyles_1);
SetStatusBar(StatusBar1);

Connect(ID_BUTTON1,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&newtestFrame::OnButton1Click);
Connect(idMenuQuit,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&newtestFrame::OnQuit);
Connect(idMenuAbout,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&newtestFrame::OnAbout);
//*)

} void newtestFrame::OnButton1Click(wxCommandEvent& event) { int i,j,testno1,testno2,testno3;

double **table1, **table2, **table3, **graphthis;
int intchoice = RadioBox1->GetSelection();

//CREATE 4 TABLES

table1 = get_matrix_space(4,8);
table2 = get_matrix_space(4,8);
table3 = get_matrix_space(4,8);
graphthis = get_matrix_space(4,8);

//CREATE 3 DATASETS TO GRAPH

for (i = 0;i <=3;++i)
{
    for(j=0;j<=6;++j)
    {
    table1[i][j]= (j+1)*10;
    table2[i][j]= 80-(j+1)*10;
    table3[i][j]= (i+1)*(j+1)*10;

    }
}
//CHOOSE A TABLE TO GRAPH BASED ON THE RADIOBOX CHOICE
for (i = 0;i <3;++i)
{
    for(j=0;j<7;++j)
    {
   if(intchoice==0) graphthis[i][j]= table1[i][j];
   if(intchoice==1) graphthis[i][j]= table2[i][j];
   if(intchoice==2) graphthis[i][j]= table3[i][j];

    }
}

// Create the data for the stacked bar chart widget
wxVector<wxString> labels;
labels.push_back("January");
labels.push_back("February");
labels.push_back("March");
labels.push_back("April");
labels.push_back("May");
labels.push_back("June");
labels.push_back("July");
wxChartsCategoricalData::ptr chartData = wxChartsCategoricalData::make_shared(labels);

// Add the first dataset
wxVector<wxDouble> points1;
for(j=1;j<7;++j)
{
testno1=graphthis[0][j];
points1.push_back(testno1);
}
wxChartsDoubleDataset::ptr dataset1(new wxChartsDoubleDataset("Dataset 1", points1));
chartData->AddDataset(dataset1);

// Add the second dataset
wxVector<wxDouble> points2;

for(j=1;j<7;++j) { testno2=graphthis[1][j]; points2.push_back(testno2); } wxChartsDoubleDataset::ptr dataset2(new wxChartsDoubleDataset("Dataset 2", points2)); chartData->AddDataset(dataset2);

// Add the third dataset
wxVector<wxDouble> points3;
for(j=1;j<7;++j)
{
testno3=graphthis[2][j];
points3.push_back(testno3);
}
wxChartsDoubleDataset::ptr dataset3(new wxChartsDoubleDataset("Dataset 3", points3));
chartData->AddDataset(dataset3);

// Create the stacked bar chart widget
wxStackedColumnChartCtrl* stackedColumnChartCtrl = new wxStackedColumnChartCtrl(Panel1,
wxID_ANY, chartData, wxPoint(180,30),wxSize(800,520));

}

double newtestFrame::get_matrix_space(int m, int n) { int i,j; double a; a = (double*) malloc(sizeof(double) m); for (i = 0; i < m; i++) { a[i] = (double) malloc(sizeof(double) * n); } for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { a[i][j] = 0.0; } }

return a;

}

newtestFrame::~newtestFrame() { //(Destroy(newtestFrame) //) }

void newtestFrame::OnQuit(wxCommandEvent& event) { Close(); }

void newtestFrame::OnAbout(wxCommandEvent& event) { wxString msg = wxbuildinfo(longf); wxMessageBox(msg, ("Welcome to...")); } `

gismowdd commented 4 years ago

Kvaz1r thanks for helping this novice wxWidgets struggle through this. Thanks for supporting the wxCharts library. I'm very happy with the quality of the charts. Removing the control and then creating a new one worked. One last question, is there anyway to convert the chart window to a bitmap so that it can be printed? I'm pretty sure the answer is no but I just thought I would ask.

Kvaz1r commented 4 years ago

One last question, is there anyway to convert the chart window to a bitmap so that it can be printed? I'm pretty sure the answer is no but I just thought I would ask.

Right, this yet one thing that was implemented only for few charts. But you can slightly modify the library for adding this. Just add

    virtual void Save(wxGraphicsContext &gc)
    {
        GetChart().Draw(gc);
    }

into wxChartCtrl and after that you will be able to draw chart onto any wxGraphicsContext.

Another option - you can make screen of your application and save it in bitmap. If you also want save a legend it will be much easier. Here is article for wxPython - How to Take a Screenshot of Your wxPython App and Print it but the code will be the same for C++.