QXlsx icon indicating copy to clipboard operation
QXlsx copied to clipboard

How to set legend name on chart

Open JasonNI7 opened this issue 4 years ago • 2 comments

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

JasonNI7 avatar Dec 09 '20 08:12 JasonNI7

Did you find the solution ?

Electronic-Boy avatar May 12 '22 12:05 Electronic-Boy

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");

Electronic-Boy avatar May 12 '22 13:05 Electronic-Boy