Hi, has anyone an idea whether it would be a big change to add a pie chart to the existing scatter, line, and bar charts? In excel I can change a bar chart to pie by simply changing the chart type on the toolbar. So my question is if it is also a simple property change in code; or whether the implementation of pie charts is more difficult? I would gladly try it myself, but do not really know what to do, as I do not understand the Excel file structure. I would welcome any suggestions where to start. If I succeed, I will gladly contribute the changes here
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Alexandr,
For a start, I took the file Scientific.xlsx from release 0.32. On the Bar chart page, I used the Excel menu option to change the bar chart to Pie.
It seems if I look from the Excel side, that only the type of chart changed, so I hope that on the code side it is also as simple as just changing one property in the code.
So instead of coding:
CChartsheet &bar_chart = book.AddChart(_T("Bar Chart"), CHART_BAR);
I suggest instead:
CChartsheet &pie_chart = book.AddChart(_T("Pie Chart"), CHART_PIE); // New enum
pie_chart.AddSeries(ser); // Same as for bar chart.
// I did not think through multiple series. I only use one
Hi,
I added a pie chart. Please take the updated library from the attachment. I also updated the MultiCharts example, please see it.
I will be grateful if you can check this update and report the results.
Thank you very much for the effort. It looks very good. Only thing I worry is the compiler error below.
I used the command below to make a Visual Studio 2017 build.
Cmake -G "Visual Studio 15 2017 Win64" . "../"
When I do a build, the following compiler errors show:
Chart.cpp:
worksheet.h(127): error C2535: 'SimpleXlsx::CWorksheet &SimpleXlsx::CWorksheet::AddCell(time_t,size_t)': member function already defined or declared
Chartsheet.cpp:
worksheet.h(127): error C2535: 'SimpleXlsx::CWorksheet &SimpleXlsx::CWorksheet::AddCell(time_t,size_t)': member function already defined or declared
Workseet.cpp:
\worksheet.h(127): error C2535: 'SimpleXlsx::CWorksheet &SimpleXlsx::CWorksheet::AddCell(time_t,size_t)': member function already defined or declared
worksheet.cpp(286): error C2084: function 'SimpleXlsx::CWorksheet &SimpleXlsx::CWorksheet::AddCell(time_t,size_t)' already has a body
It seems like in Worksheet.cpp, the compiler takes the following as duplicates of the same function:
Line 257: CWorksheet & CWorksheet::AddCell( time_t value, size_t style_id )
and
Line 286: CWorksheet & CWorksheet::AddCell( int64_t value, size_t style_id )
Just to continue testing, I commented out the int64_t version in both Worksheet.h and Worksheet.cpp, and then the build succeeded, and I got a .lib (static) file as output.
I was then able to build a program using scientific.cpp in the samples folder, and when I run it, the program creates a file 'scientific.xlsx'
When I open that file in Excel, I get the following message:
"We found a problem with some content in 'Scientific.xlsx'. Do you want us to try to recover as much as we can?"
Excel then displayed a window: "Removed part: /xl/drawings/drawing4.xml part. (Drawing shape)".
When I open the 'Scientific.xlsx' you packaged in the zip file, Excel opens without showing any issue.
When I click on the pie chart page (both versions of Scientific.xlsx), it looks perfect.
So, all in all, THANK YOU, and congratulations, it looks very good!
Sorry, I missed that you mention Multicharts.cpp. I built that, but the resulting spreadsheet has the data page, a line chart page, and the third (Data2) is also a line like a sine wave. I see no pie chart in that spreadsheet file.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks a lot for operational testing and a detailed description of the problems.
I used MinGW, so I will try to check the compilation using Visual Studio a bit later.
Sorry, I made a mistake with the Multicharts.cpp, of course, it was about Scientific.cpp.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Willem,
I was unable to repeat the error with broken content. I used Visual Studio Community 2017 (v15.9.17) and Microsoft Excel 2010 (v14.0.7116.5000).
Can you attach your "Scientific.xlsx" file with the problem?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Alexandr
Thank you for your effort. I attach here the Excel file with the problem (64-bit release build. I did not try 32-bit ). I created it with Visual Studio Community Edition v15.9.7. I use Excel 2016, version 1910.
I also tried using the new Visual Studio 2019 Community. Same problem, both with 32-bit and 64 bit (only tried debug build).
I then used the Windows Subsystem for Linux (Ubuntu) and compiled it with Clang 9.0.0. I ran it from the bash shell and opened the file in Windows with Excel - no issue.
A file compare with the Windows-generated file shows differences in the two Excel files.
If I unxip both XSLX files, I find differences in the /docProps/core.xml file. also in charts/chart2.xml, and in worksheets/sheet1 and sheet2. I cannot however interpret what the issue is in the one file.
I attach both the VS2017 and Clang generated Excel files for you.
I now installed Clang (seems lik v8.0) in Windows, using the Visual Studio 2019, Community edition installer. I opened a previous Visual Studio solution and re-targeted it to Clang and then the spreadsheet from the program is fine. So I suspect it is relatedto the Microsoft compiler. I will play around and see if I can find something.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I think I might perhaps have some news. I begin to think the pie chart actually works fine, and that the issue I see could perhaps be from the scatter chart.
I unzipped the two excel spreadsheets and investigated "chart2". The attached compare shows differences. When I open Chart2.cpp and set a breakpoint on line 267 as shown, I see the same name as printed in the file compare tool (I used winmerge). So the MSVC compiler starts the name with '?' and Clang has 'Ï' instead. But then I noticed the code generates the pie chart after this.
So then in scientific.cpp I commented out all the charts, and compiled only with the pie chart, like this:
//AddLineChart( book, sheet1, cl_lib, gs10_lib );
//AddScatterChart( book, sheet, sheet1, cl_lib, gs10_lib );
//AddBarChart( book, sheet );
AddPieChart( book, sheet ); // Now I only test with this.
Using this, the spreadsheet is fine, with both compilers. It then has only the one sheet for the pie, and Excel does not complain with a message when I open it.
Then I tried this:
//AddLineChart( book, sheet1, cl_lib, gs10_lib );
AddScatterChart( book, sheet, sheet1, cl_lib, gs10_lib );
//AddBarChart( book, sheet );
AddPieChart( book, sheet ); // Now I only test with this.
Again Excel started complaining with the spreadsheet if I compiled the program with MSVC.
Last try:
AddLineChart( book, sheet1, cl_lib, gs10_lib );
//AddScatterChart( book, sheet, sheet1, cl_lib, gs10_lib );
AddBarChart( book, sheet );
AddPieChart( book, sheet ); // Now I only test with this.
Again all seem fine with the spreadsheet if I compile with MSVC.
I will do some more tests this week and post if I find an issue with the pie chart again.
Hi Willem,
Thanks so much for such detailed information.
I have not had time to examine your files, but I already have one thought.
Please find the AddScatterChart function in the Scientific.cpp file and at the very end replace this:
Hi Willem,
Thanks again for testing. I apologize for my carelessness in preparing this example. It is surprising that this problem is no one there before.
In the attachment is an updated version of the library.
Please note that the CWorksheet::AddCell(time_t) method has been removed. But the CWorksheet::AddCell(CellDataTime) method remained.
Hi, has anyone an idea whether it would be a big change to add a pie chart to the existing scatter, line, and bar charts? In excel I can change a bar chart to pie by simply changing the chart type on the toolbar. So my question is if it is also a simple property change in code; or whether the implementation of pie charts is more difficult? I would gladly try it myself, but do not really know what to do, as I do not understand the Excel file structure. I would welcome any suggestions where to start. If I succeed, I will gladly contribute the changes here
Hi,
Please attach examples of Excel files of what you want. I will try to figure out how to do this in the library.
Hi Alexandr,
For a start, I took the file Scientific.xlsx from release 0.32. On the Bar chart page, I used the Excel menu option to change the bar chart to Pie.
It seems if I look from the Excel side, that only the type of chart changed, so I hope that on the code side it is also as simple as just changing one property in the code.
So instead of coding:
CChartsheet &bar_chart = book.AddChart(_T("Bar Chart"), CHART_BAR);
I suggest instead:
CChartsheet &pie_chart = book.AddChart(_T("Pie Chart"), CHART_PIE); // New enum
pie_chart.AddSeries(ser); // Same as for bar chart.
// I did not think through multiple series. I only use one
Thanks!
Thanks for the explanation and example. I will try to add a pie chart. It will take some time.
Hi,
I added a pie chart. Please take the updated library from the attachment. I also updated the MultiCharts example, please see it.
I will be grateful if you can check this update and report the results.
Hi Alexandr.
Thank you very much for the effort. It looks very good. Only thing I worry is the compiler error below.
I used the command below to make a Visual Studio 2017 build.
Cmake -G "Visual Studio 15 2017 Win64" . "../"
When I do a build, the following compiler errors show:
Chart.cpp:
worksheet.h(127): error C2535: 'SimpleXlsx::CWorksheet &SimpleXlsx::CWorksheet::AddCell(time_t,size_t)': member function already defined or declared
Chartsheet.cpp:
worksheet.h(127): error C2535: 'SimpleXlsx::CWorksheet &SimpleXlsx::CWorksheet::AddCell(time_t,size_t)': member function already defined or declared
Workseet.cpp:
\worksheet.h(127): error C2535: 'SimpleXlsx::CWorksheet &SimpleXlsx::CWorksheet::AddCell(time_t,size_t)': member function already defined or declared
worksheet.cpp(286): error C2084: function 'SimpleXlsx::CWorksheet &SimpleXlsx::CWorksheet::AddCell(time_t,size_t)' already has a body
It seems like in Worksheet.cpp, the compiler takes the following as duplicates of the same function:
Line 257: CWorksheet & CWorksheet::AddCell( time_t value, size_t style_id )
and
Line 286: CWorksheet & CWorksheet::AddCell( int64_t value, size_t style_id )
Just to continue testing, I commented out the int64_t version in both Worksheet.h and Worksheet.cpp, and then the build succeeded, and I got a .lib (static) file as output.
I was then able to build a program using scientific.cpp in the samples folder, and when I run it, the program creates a file 'scientific.xlsx'
When I open that file in Excel, I get the following message:
"We found a problem with some content in 'Scientific.xlsx'. Do you want us to try to recover as much as we can?"
Excel then displayed a window: "Removed part: /xl/drawings/drawing4.xml part. (Drawing shape)".
When I open the 'Scientific.xlsx' you packaged in the zip file, Excel opens without showing any issue.
When I click on the pie chart page (both versions of Scientific.xlsx), it looks perfect.
So, all in all, THANK YOU, and congratulations, it looks very good!
Kind regards
Willem
Sorry, I missed that you mention Multicharts.cpp. I built that, but the resulting spreadsheet has the data page, a line chart page, and the third (Data2) is also a line like a sine wave. I see no pie chart in that spreadsheet file.
Hi Willem,
Thanks a lot for operational testing and a detailed description of the problems.
I used MinGW, so I will try to check the compilation using Visual Studio a bit later.
Sorry, I made a mistake with the Multicharts.cpp, of course, it was about Scientific.cpp.
Hi Willem,
I was unable to repeat the error with broken content. I used Visual Studio Community 2017 (v15.9.17) and Microsoft Excel 2010 (v14.0.7116.5000).
Can you attach your "Scientific.xlsx" file with the problem?
Hi Alexandr
Thank you for your effort. I attach here the Excel file with the problem (64-bit release build. I did not try 32-bit ). I created it with Visual Studio Community Edition v15.9.7. I use Excel 2016, version 1910.
I also tried using the new Visual Studio 2019 Community. Same problem, both with 32-bit and 64 bit (only tried debug build).
I then used the Windows Subsystem for Linux (Ubuntu) and compiled it with Clang 9.0.0. I ran it from the bash shell and opened the file in Windows with Excel - no issue.
A file compare with the Windows-generated file shows differences in the two Excel files.
If I unxip both XSLX files, I find differences in the /docProps/core.xml file. also in charts/chart2.xml, and in worksheets/sheet1 and sheet2. I cannot however interpret what the issue is in the one file.
I attach both the VS2017 and Clang generated Excel files for you.
I now installed Clang (seems lik v8.0) in Windows, using the Visual Studio 2019, Community edition installer. I opened a previous Visual Studio solution and re-targeted it to Clang and then the spreadsheet from the program is fine. So I suspect it is relatedto the Microsoft compiler. I will play around and see if I can find something.
Hi Alexandr
I think I might perhaps have some news. I begin to think the pie chart actually works fine, and that the issue I see could perhaps be from the scatter chart.
I unzipped the two excel spreadsheets and investigated "chart2". The attached compare shows differences. When I open Chart2.cpp and set a breakpoint on line 267 as shown, I see the same name as printed in the file compare tool (I used winmerge). So the MSVC compiler starts the name with '?' and Clang has 'Ï' instead. But then I noticed the code generates the pie chart after this.
So then in scientific.cpp I commented out all the charts, and compiled only with the pie chart, like this:
//AddLineChart( book, sheet1, cl_lib, gs10_lib );
//AddScatterChart( book, sheet, sheet1, cl_lib, gs10_lib );
//AddBarChart( book, sheet );
AddPieChart( book, sheet ); // Now I only test with this.
Using this, the spreadsheet is fine, with both compilers. It then has only the one sheet for the pie, and Excel does not complain with a message when I open it.
Then I tried this:
//AddLineChart( book, sheet1, cl_lib, gs10_lib );
AddScatterChart( book, sheet, sheet1, cl_lib, gs10_lib );
//AddBarChart( book, sheet );
AddPieChart( book, sheet ); // Now I only test with this.
Again Excel started complaining with the spreadsheet if I compiled the program with MSVC.
Last try:
AddLineChart( book, sheet1, cl_lib, gs10_lib );
//AddScatterChart( book, sheet, sheet1, cl_lib, gs10_lib );
AddBarChart( book, sheet );
AddPieChart( book, sheet ); // Now I only test with this.
Again all seem fine with the spreadsheet if I compile with MSVC.
I will do some more tests this week and post if I find an issue with the pie chart again.
Sorry, Chart.cpp, not Chart2.cpp
Hi Willem,
Thanks so much for such detailed information.
I have not had time to examine your files, but I already have one thought.
Please find the AddScatterChart function in the Scientific.cpp file and at the very end replace this:
with
And try with MSVC again.
Hi Alexandr
Thank you, it looks like this fixes the issue. I tried the MS compiler both with Visual Studio 2017 and 2019 and it looks fine now.
Hi Willem,
Thanks again for testing. I apologize for my carelessness in preparing this example. It is surprising that this problem is no one there before.
In the attachment is an updated version of the library.
Please note that the CWorksheet::AddCell(time_t) method has been removed. But the CWorksheet::AddCell(CellDataTime) method remained.
Hi Alexandr
Thank you for all the effort.
I made a build with Beta3 and it seems fine to me.
The graphs look great!
Willem