1
0
mirror of https://github.com/QtExcel/QXlsx.git synced 2025-01-30 05:02:52 +08:00

update loading chart

This commit is contained in:
Jay Two 2019-02-26 16:59:31 +09:00
parent b13f772067
commit 8c90796fee
4 changed files with 32 additions and 25 deletions

View File

@ -367,12 +367,10 @@ bool ChartPrivate::loadXmlPlotArea(QXmlStreamReader &reader)
bool ChartPrivate::loadXmlPlotAreaElement(QXmlStreamReader &reader)
{
if (reader.name() == QLatin1String("layout"))
{
//!ToDo
// layout
reader.skipCurrentElement();
}
else if (reader.name().endsWith(QLatin1String("Chart")))
{
@ -385,38 +383,41 @@ bool ChartPrivate::loadXmlPlotAreaElement(QXmlStreamReader &reader)
}
else if (reader.name() == QLatin1String("catAx")) // choose one : catAx, dateAx, serAx, valAx
{
qDebug() << "loadXmlAxisCatAx()";
loadXmlAxisCatAx(reader);
}
else if (reader.name() == QLatin1String("dateAx")) // choose one : catAx, dateAx, serAx, valAx
{
qDebug() << "loadXmlAxisDateAx()";
loadXmlAxisDateAx(reader);
}
else if (reader.name() == QLatin1String("serAx")) // choose one : catAx, dateAx, serAx, valAx
{
qDebug() << "loadXmlAxisSerAx()";
loadXmlAxisSerAx(reader);
}
else if (reader.name() == QLatin1String("valAx")) // choose one : catAx, dateAx, serAx, valAx
{
// qDebug() << QTime::currentTime() << reader.name().toString();
qDebug() << "loadXmlAxisValAx()";
loadXmlAxisValAx(reader);
}
else if (reader.name() == QLatin1String("dTable"))
{
//!ToDo
// dTable "CT_DTable"
reader.skipCurrentElement();
// reader.skipCurrentElement();
}
else if (reader.name() == QLatin1String("spPr"))
{
//!ToDo
// spPr "a:CT_ShapeProperties"
reader.skipCurrentElement();
// reader.skipCurrentElement();
}
else if (reader.name() == QLatin1String("extLst"))
{
//!ToDo
// extLst "CT_ExtensionList"
reader.skipCurrentElement();
// reader.skipCurrentElement();
}
return true;
@ -872,7 +873,8 @@ void ChartPrivate::saveXmlBarChart(QXmlStreamWriter &writer) const
}
//Note: Bar3D have 2~3 axes
Q_ASSERT(axisList.size()==2 || (axisList.size()==3 && chartType==Chart::CT_Bar3DChart));
int axisListSize = axisList.size();
Q_ASSERT( axisListSize == 2 || ( axisListSize == 3 && chartType == Chart::CT_Bar3DChart ) );
for ( int i = 0 ; i < axisList.size() ; ++i )
{
@ -1110,8 +1112,8 @@ bool ChartPrivate::loadXmlAxisValAx(QXmlStreamReader &reader)
if ( ! loadXmlAxisEG_AxShared( reader, axis ) )
{
// qDebug() << "failed to load EG_AxShared";
// return false;
qDebug() << "failed to load EG_AxShared";
return false;
}
//!TODO: load element
@ -1151,7 +1153,8 @@ bool ChartPrivate::loadXmlAxisValAx(QXmlStreamReader &reader)
bool ChartPrivate::loadXmlAxisEG_AxShared(QXmlStreamReader &reader, XlsxAxis* axis)
{
Q_ASSERT( NULL != axis );
Q_ASSERT(reader.name() == QLatin1String("valAx"));
Q_ASSERT( reader.name().endsWith("Ax") );
QString name = reader.name().toString(); //
while ( !reader.atEnd() )
{
@ -1249,7 +1252,7 @@ bool ChartPrivate::loadXmlAxisEG_AxShared(QXmlStreamReader &reader, XlsxAxis* ax
// reader.readNext();
}
else if ( reader.tokenType() == QXmlStreamReader::EndElement &&
reader.name() == "valAx" )
reader.name().toString() == name )
{
break;
}

View File

@ -23,56 +23,56 @@ int chart()
//![1]
Chart *pieChart = xlsx.insertChart(3, 3, QSize(300, 300));
pieChart->setChartType(Chart::CT_Pie);
pieChart->setChartType(Chart::CT_PieChart);
pieChart->addSeries(CellRange("A1:A9"));
pieChart->addSeries(CellRange("B1:B9"));
pieChart->addSeries(CellRange("C1:C9"));
Chart *pie3DChart = xlsx.insertChart(3, 9, QSize(300, 300));
pie3DChart->setChartType(Chart::CT_Pie3D);
pie3DChart->setChartType(Chart::CT_Pie3DChart);
pie3DChart->addSeries(CellRange("A1:C9"));
Chart *barChart = xlsx.insertChart(23, 3, QSize(300, 300));
barChart->setChartType(Chart::CT_Bar);
barChart->setChartType(Chart::CT_BarChart);
barChart->addSeries(CellRange("A1:C9"));
Chart *bar3DChart = xlsx.insertChart(23, 9, QSize(300, 300));
bar3DChart->setChartType(Chart::CT_Bar3D);
bar3DChart->setChartType(Chart::CT_Bar3DChart);
bar3DChart->addSeries(CellRange("A1:C9"));
// issue #10 is fixed. https://github.com/j2doll/QXlsx/issues/10
// {{
Chart *lineChart = xlsx.insertChart(43, 3, QSize(300, 300));
lineChart->setChartType(Chart::CT_Line);
lineChart->setChartType(Chart::CT_LineChart);
lineChart->addSeries(CellRange("A1:C9"));
Chart *line3DChart = xlsx.insertChart(43, 9, QSize(300, 300));
line3DChart->setChartType(Chart::CT_Line3D);
line3DChart->setChartType(Chart::CT_Line3DChart);
line3DChart->addSeries(CellRange("A1:C9"));
Chart *areaChart = xlsx.insertChart(63, 3, QSize(300, 300));
areaChart->setChartType(Chart::CT_Area);
areaChart->setChartType(Chart::CT_AreaChart);
areaChart->addSeries(CellRange("A1:C9"));
Chart *area3DChart = xlsx.insertChart(63, 9, QSize(300, 300));
area3DChart->setChartType(Chart::CT_Area3D);
area3DChart->setChartType(Chart::CT_Area3DChart);
area3DChart->addSeries(CellRange("A1:C9"));
// }}
Chart *scatterChart = xlsx.insertChart(83, 3, QSize(300, 300));
scatterChart->setChartType(Chart::CT_Scatter);
scatterChart->setChartType(Chart::CT_ScatterChart);
//Will generate three lines.
scatterChart->addSeries(CellRange("A1:A9"));
scatterChart->addSeries(CellRange("B1:B9"));
scatterChart->addSeries(CellRange("C1:C9"));
Chart *scatterChart_2 = xlsx.insertChart(83, 9, QSize(300, 300));
scatterChart_2->setChartType(Chart::CT_Scatter);
scatterChart_2->setChartType(Chart::CT_ScatterChart);
//Will generate two lines.
scatterChart_2->addSeries(CellRange("A1:C9"));
Chart *doughnutChart = xlsx.insertChart(103, 3, QSize(300, 300));
doughnutChart->setChartType(Chart::CT_Doughnut);
doughnutChart->setChartType(Chart::CT_DoughnutChart);
doughnutChart->addSeries(CellRange("A1:C9"));
//![1]
@ -81,6 +81,10 @@ int chart()
//![2]
Document xlsx2("chart1.xlsx");
xlsx2.saveAs("chart2.xlsx");
if ( xlsx2.load() )
{
xlsx2.saveAs("chart2.xlsx");
}
return 0;
}

View File

@ -20,7 +20,7 @@ int chartsheet()
xlsx.addSheet("Chart1", AbstractSheet::ST_ChartSheet);
Chartsheet *sheet = static_cast<Chartsheet*>(xlsx.currentSheet());
Chart *barChart = sheet->chart();
barChart->setChartType(Chart::CT_Bar);
barChart->setChartType(Chart::CT_BarChart);
barChart->addSeries(CellRange("A1:A9"), xlsx.sheet("Sheet1"));
//![1]

View File

@ -270,7 +270,7 @@ void DoChart(bool isTest)
xlsx.addSheet("Chart1", AbstractSheet::ST_ChartSheet);
Chartsheet *sheet = static_cast<Chartsheet*>(xlsx.currentSheet());
Chart *barChart = sheet->chart();
barChart->setChartType(Chart::CT_Bar);
barChart->setChartType(Chart::CT_BarChart);
barChart->addSeries(CellRange("A1:A9"), xlsx.sheet("Sheet1"));
//![1]