MSChart labels
-
Hi I've read the article in Code project about the mschart and how to set data. Now I would like to know how to set the labels. Can anyone help? Thanks
G'Day Anon I may have the answer for you though I'm not 100% sure because I'm yet to get it working myself - but I have run out of time for the moment. using the example on code project I have added the following code when the GO button is pressed. I have placed it just before the chart is refreshed. The first bit sets the legend (only did 1 to see if it worked) CVcPlot Plot = m_Chart.GetPlot(); CVcSeriesCollection SeriesCollection = Plot.GetSeriesCollection(); CVcSeries Series = SeriesCollection.GetItem(1); Series.SetLegendText(_T("New Text")); The next bit was to do the labels for each point on the axis. It is incomplete and not quite working but hopefully it will give you an idea and you can let me know how to fix it :-) I am getting a bad function argument error when calling SetColumnLabel or SetRowLabel - something to do with my indexes I think. CVcDataGrid DataGrid = m_Chart.GetDataGrid(); short i; CString strLabel; short nRows = DataGrid.GetRowLabelCount(); short nColumns = DataGrid.GetColumnLabelCount(); /* for (i=0; i
-
G'Day Anon I may have the answer for you though I'm not 100% sure because I'm yet to get it working myself - but I have run out of time for the moment. using the example on code project I have added the following code when the GO button is pressed. I have placed it just before the chart is refreshed. The first bit sets the legend (only did 1 to see if it worked) CVcPlot Plot = m_Chart.GetPlot(); CVcSeriesCollection SeriesCollection = Plot.GetSeriesCollection(); CVcSeries Series = SeriesCollection.GetItem(1); Series.SetLegendText(_T("New Text")); The next bit was to do the labels for each point on the axis. It is incomplete and not quite working but hopefully it will give you an idea and you can let me know how to fix it :-) I am getting a bad function argument error when calling SetColumnLabel or SetRowLabel - something to do with my indexes I think. CVcDataGrid DataGrid = m_Chart.GetDataGrid(); short i; CString strLabel; short nRows = DataGrid.GetRowLabelCount(); short nColumns = DataGrid.GetColumnLabelCount(); /* for (i=0; i
Hi Richard, Sorry that I'm only answering now, it's just that I've been busy and only had the time to do this now. I tried what you suggested and also get the same "bad function argument" error. So I tried the following: short index; for ( i = 1; i < 11; i++ ) { //strLabel.Format("row %d", i); // strLabel = "Row Text"; index = i * 2; // DataGrid.SetColumnLabel(index, 1, ""); strLabel = DataGrid.GetColumnLabel(index, 1); } And I get all the correct column names, i.e. R1, R2, R3, ... R10. It almost seems to be the actual string variable that seems to give the problem??? Still trying. Have you had any success? Rui Rui
-
G'Day Anon I may have the answer for you though I'm not 100% sure because I'm yet to get it working myself - but I have run out of time for the moment. using the example on code project I have added the following code when the GO button is pressed. I have placed it just before the chart is refreshed. The first bit sets the legend (only did 1 to see if it worked) CVcPlot Plot = m_Chart.GetPlot(); CVcSeriesCollection SeriesCollection = Plot.GetSeriesCollection(); CVcSeries Series = SeriesCollection.GetItem(1); Series.SetLegendText(_T("New Text")); The next bit was to do the labels for each point on the axis. It is incomplete and not quite working but hopefully it will give you an idea and you can let me know how to fix it :-) I am getting a bad function argument error when calling SetColumnLabel or SetRowLabel - something to do with my indexes I think. CVcDataGrid DataGrid = m_Chart.GetDataGrid(); short i; CString strLabel; short nRows = DataGrid.GetRowLabelCount(); short nColumns = DataGrid.GetColumnLabelCount(); /* for (i=0; i
Hi Richard, I tried the following: DataGrid.SetColumnLabel(1, 1, "Column 1"); strLabel = DataGrid.GetColumnLabel(1, 1); AfxMessageBox(strLabel); This enables the C1 text in the datagrid to be changed. This seems to be the name of the first set of data. But I'm still not able to change the Column labels. Does anyone have a clue how to do it? Regards Rui
-
G'Day Anon I may have the answer for you though I'm not 100% sure because I'm yet to get it working myself - but I have run out of time for the moment. using the example on code project I have added the following code when the GO button is pressed. I have placed it just before the chart is refreshed. The first bit sets the legend (only did 1 to see if it worked) CVcPlot Plot = m_Chart.GetPlot(); CVcSeriesCollection SeriesCollection = Plot.GetSeriesCollection(); CVcSeries Series = SeriesCollection.GetItem(1); Series.SetLegendText(_T("New Text")); The next bit was to do the labels for each point on the axis. It is incomplete and not quite working but hopefully it will give you an idea and you can let me know how to fix it :-) I am getting a bad function argument error when calling SetColumnLabel or SetRowLabel - something to do with my indexes I think. CVcDataGrid DataGrid = m_Chart.GetDataGrid(); short i; CString strLabel; short nRows = DataGrid.GetRowLabelCount(); short nColumns = DataGrid.GetColumnLabelCount(); /* for (i=0; i
hi Richard, The following works: COleSafeArray saRet; CString strLabel = ""; DWORD numElements[] = {10, 1}; // 10x10 //DWORD numElements[] = {10}; // Create the safe-array... saRet.Create(VT_R8, 2, numElements); // Initialize it with values... long index[2]; for(index[0] = 0; index[0] < 10; index[0]++) { for(index[1] = 0; index[1] < 1; index[1]++) { double val = index[0]*10; saRet.PutElement(index, &val); } } // Return the safe-array encapsulated in a VARIANT... m_Chart.SetChartData(saRet.Detach()); m_Chart.SetChartType(3); CVcPlot Plot = m_Chart.GetPlot(); CVcSeriesCollection SeriesCollection = Plot.GetSeriesCollection(); CVcSeries Series = SeriesCollection.GetItem(1); Series.SetLegendText(_T("New Text")); CVcDataGrid DataGrid = m_Chart.GetDataGrid(); short i; short nRows = DataGrid.GetRowLabelCount(); short nColumns = DataGrid.GetColumnLabelCount(); /* for (i=0; i { strLabel.Format("col %d", i); DataGrid.SetColumnLabel(i, 1, strLabel); } */ short j; // DataGrid.SetColumnLabelCount(10); // count = DataGrid.GetColumnLabelCount(); for ( i = 1; i < 6; i++ ) { //strLabel.Format("row %d", i); strLabel = "Row Text"; j = i * 2; // DataGrid.SetColumnLabel(j, 1, strLabel); strLabel = DataGrid.GetColumnLabel(j, 1); //AfxMessageBox(strLabel); DataGrid.SetRowLabel(i, 1, "Row"); strLabel = DataGrid.GetRowLabel(i, 1); } m_Chart.SetShowLegend(TRUE); m_Chart.Refresh(); Try it. Thanks for your help Rui
-
hi Richard, The following works: COleSafeArray saRet; CString strLabel = ""; DWORD numElements[] = {10, 1}; // 10x10 //DWORD numElements[] = {10}; // Create the safe-array... saRet.Create(VT_R8, 2, numElements); // Initialize it with values... long index[2]; for(index[0] = 0; index[0] < 10; index[0]++) { for(index[1] = 0; index[1] < 1; index[1]++) { double val = index[0]*10; saRet.PutElement(index, &val); } } // Return the safe-array encapsulated in a VARIANT... m_Chart.SetChartData(saRet.Detach()); m_Chart.SetChartType(3); CVcPlot Plot = m_Chart.GetPlot(); CVcSeriesCollection SeriesCollection = Plot.GetSeriesCollection(); CVcSeries Series = SeriesCollection.GetItem(1); Series.SetLegendText(_T("New Text")); CVcDataGrid DataGrid = m_Chart.GetDataGrid(); short i; short nRows = DataGrid.GetRowLabelCount(); short nColumns = DataGrid.GetColumnLabelCount(); /* for (i=0; i { strLabel.Format("col %d", i); DataGrid.SetColumnLabel(i, 1, strLabel); } */ short j; // DataGrid.SetColumnLabelCount(10); // count = DataGrid.GetColumnLabelCount(); for ( i = 1; i < 6; i++ ) { //strLabel.Format("row %d", i); strLabel = "Row Text"; j = i * 2; // DataGrid.SetColumnLabel(j, 1, strLabel); strLabel = DataGrid.GetColumnLabel(j, 1); //AfxMessageBox(strLabel); DataGrid.SetRowLabel(i, 1, "Row"); strLabel = DataGrid.GetRowLabel(i, 1); } m_Chart.SetShowLegend(TRUE); m_Chart.Refresh(); Try it. Thanks for your help Rui
G'Day Rui, I'd forgotten all about this! I'll dig out the code I was playing with at the time and try it out. Thanks for your help! Richard.