QtExcel / QXlsx

Excel file(*.xlsx) reader/writer library using Qt 5 or 6. Descendant of QtXlsxWriter.
https://qtexcel.github.io/QXlsx/
MIT License
1.16k stars 359 forks source link

How to set legend name on chart #125

Open JasonNI7 opened 3 years ago

JasonNI7 commented 3 years ago

Hi! I'm working on my project with QXlsx and thanks very much for this sharing!

Just a issue that I found.

After I addSeries and setChartLegend, chart and legend are display on excel successfully, but the legend name I couldn't set. Is there any method to set these legend name?

Thanks again!!

Jason

Electronic-Boy commented 2 years ago

Did you find the solution ?

Electronic-Boy commented 2 years ago

i found

xlsx.write(1, 1, "Temperature");   //A1
    xlsx.write(1, 2, "Humidity");   //B1:
    xlsx.write(1, 3, "Solar Load");   //C1
    for (int i=1; i<10; ++i)
    {
        xlsx.write(i+1, 1, i+50);   //A2:A10
        xlsx.write(i+1, 2, i+20); //B2:B10
        xlsx.write(i+1, 3, i+10); //C2:C10
    }
    QXlsx::Chart *lineChart = xlsx.insertChart(43, 3, QSize(300, 300));
    lineChart->setChartType(QXlsx::Chart::CT_LineChart);
    lineChart->setChartTitle(tr("Temp-Hum-Solar Graph"));
    lineChart->setGridlinesEnable(true,false);
    lineChart->setChartLegend(QXlsx::Chart::ChartAxisPos::Bottom,false);
    lineChart->setAxisTitle(QXlsx::Chart::ChartAxisPos::Bottom, "Time in Seconds");
    lineChart->addSeries(CellRange("A1:C10"),nullptr,true,false,true);

    xlsx.saveAs("chart1.xlsx");