From 01d2a7083c004a1a1518f6109f786ea77f77dd20 2012-12-11 12:08:36 From: Marek Rosa Date: 2012-12-11 12:08:36 Subject: [PATCH] logvalueaxis and multiaxis examples documented --- diff --git a/doc/src/examples-logvalueaxis.qdoc b/doc/src/examples-logvalueaxis.qdoc new file mode 100644 index 0000000..fd9899f --- /dev/null +++ b/doc/src/examples-logvalueaxis.qdoc @@ -0,0 +1,30 @@ +/*! + \example examples/logvalueaxis + \title Logarithmic axis example + \subtitle + + The example shows how to use QLogValueAxis. + + \image examples_logvalueaxis.png + + Create QLineSeries instance and add some data to it. + + \snippet ../examples/logvalueaxis/main.cpp 1 + + To present the data on the char we need QChart instance. Add the series to it, hide the legend and set the title of the chart. + + \snippet ../examples/logvalueaxis/main.cpp 2 + + Create the axes. Add them to the chart and attach to the series. + + \snippet ../examples/logvalueaxis/main.cpp 3 + + Then create a QChartView object with QChart as a parameter. Enable antialiasing to have the rendered line look nicer. + + \snippet ../examples/logvalueaxis/main.cpp 4 + + Chart is ready to be shown. + + \snippet ../examples/logvalueaxis/main.cpp 5 + +*/ diff --git a/doc/src/examples-multiaxis.qdoc b/doc/src/examples-multiaxis.qdoc new file mode 100644 index 0000000..d618ba1 --- /dev/null +++ b/doc/src/examples-multiaxis.qdoc @@ -0,0 +1,36 @@ +/*! + \example examples/multiaxis + \title Multiple axes example + \subtitle + + The example shows how to create simple chart with two vertical axes. One for each series. + + \image examples_multiaxis.png + + Create QChart instance, hide the legend of the chart and set its title. + + \snippet ../examples/multiaxis/main.cpp 1 + + Create a QValueAxis instance that will be used as a horizontal axis by both series and add it the bottom of the chart. + Axis can be sharted between many series, but each series can have only one vertical and horizontal axis. + + \snippet ../examples/multiaxis/main.cpp 2 + + Create the first series, add the data to it, finally add the series to the chart. Instantiate its own Y-axis, add it to the chart then attach both the common X-axis and the series specific Y-axis. + In this example the color of the axis line is set to be the same as the color of the series to make it possible to distinguish which axis is attached to which series. + + \snippet ../examples/multiaxis/main.cpp 3 + + Similarly prepare another series. This time different axis type is used. Additionally grid lines color is also set to be the same as the color of the series. + + \snippet ../examples/multiaxis/main.cpp 4 + + Create a QChartView object with QChart as a parameter. Enanle Antialiasing to have the rendered splines look nicer. + + \snippet ../examples/multiaxis/main.cpp 5 + + Chart is ready to be shown. + + \snippet ../examples/multiaxis/main.cpp 6 + +*/ diff --git a/doc/src/examples.qdoc b/doc/src/examples.qdoc index 3c9551f..a2773c9 100644 --- a/doc/src/examples.qdoc +++ b/doc/src/examples.qdoc @@ -70,11 +70,20 @@ + Logarythmic axis Model Data - Percent Bar Chart + Logarythmix axis Model Data + + + + Multiple axes + Percent Bar Chart + + + Multiple axes Percent Bar Chart diff --git a/examples/logvalueaxis/main.cpp b/examples/logvalueaxis/main.cpp index 275e034..6eb53be 100644 --- a/examples/logvalueaxis/main.cpp +++ b/examples/logvalueaxis/main.cpp @@ -36,14 +36,14 @@ int main(int argc, char *argv[]) *series << QPointF(1, 1) << QPointF(2, 73) << QPointF(3, 268) << QPointF(4, 17) << QPointF(5, 4325) << QPointF(6, 723); //![1] - //![3] + //![2] QChart *chart = new QChart(); chart->addSeries(series); chart->legend()->hide(); - chart->setTitle("QLogValueAxis chart example"); - //![3] + chart->setTitle("Logarithmic axis example"); + //![2] - //![4] + //![3] QValueAxis *axisX = new QValueAxis; axisX->setTitleText("Data point"); axisX->setTickCount(6); @@ -54,14 +54,15 @@ int main(int argc, char *argv[]) QLogValueAxis *axisY = new QLogValueAxis; axisY->setLabelFormat("%g"); axisY->setTitleText("Values"); + axisY->setBase(8); chart->addAxis(axisY, Qt::AlignLeft); series->attachAxis(axisY); - //![4] + //![3] - //![5] + //![4] QChartView *chartView = new QChartView(chart); chartView->setRenderHint(QPainter::Antialiasing); - //![5] + //![4] //![6] QMainWindow window; diff --git a/examples/multiaxis/main.cpp b/examples/multiaxis/main.cpp index 0f81776..a52480e 100644 --- a/examples/multiaxis/main.cpp +++ b/examples/multiaxis/main.cpp @@ -33,10 +33,18 @@ int main(int argc, char *argv[]) QApplication a(argc, argv); //![1] - QChart *chart = new QChart(); + QChart *chart = new QChart(); + chart->legend()->hide(); + chart->setTitle("Multiaxis chart example"); + //![1] + + //![2] QValueAxis *axisX = new QValueAxis; axisX->setTickCount(10); + chart->addAxis(axisX, Qt::AlignBottom); + //![2] + //![3] QSplineSeries *series = new QSplineSeries; *series << QPointF(1, 5) << QPointF(3.5, 18) << QPointF(4.8, 7.5) << QPointF(10, 2.5); chart->addSeries(series); @@ -44,11 +52,12 @@ int main(int argc, char *argv[]) QValueAxis *axisY = new QValueAxis; axisY->setLinePenColor(series->pen().color()); - chart->addAxis(axisX, Qt::AlignBottom); chart->addAxis(axisY, Qt::AlignLeft); series->attachAxis(axisX); series->attachAxis(axisY); + //![3] + //![4] series = new QSplineSeries; *series << QPointF(1, 0.5) << QPointF(1.5, 4.5) << QPointF(2.4, 2.5) << QPointF(4.3, 12.5) << QPointF(5.2, 3.5) << QPointF(7.4, 16.5) << QPointF(8.3, 7.5) << QPointF(10, 17); @@ -64,26 +73,19 @@ int main(int argc, char *argv[]) chart->addAxis(axisY3, Qt::AlignRight); series->attachAxis(axisX); series->attachAxis(axisY3); - - //![2] - - //![3] - chart->legend()->hide(); - chart->setTitle("Multiaxis chart example"); - //![3] - //![4] + + //![5] QChartView *chartView = new QChartView(chart); chartView->setRenderHint(QPainter::Antialiasing); - //![4] - - //![5] + + //![6] QMainWindow window; window.setCentralWidget(chartView); window.resize(800, 600); window.show(); - //![5] + //![6] return a.exec(); }