Sophie

Sophie

distrib > Mageia > 7 > i586 > by-pkgid > bc3b37a19f14c9d212f32b1359cbcf6a > files > 413

qtcharts5-doc-5.12.6-1.mga7.noarch.rpm

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- examples-qmlchart.qdoc -->
  <title>Qml Charts Example | Qt Charts 5.12.6</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td >Qt 5.12</td><td ><a href="qtcharts-index.html">Qt Charts</a></td><td ><a href="qtcharts-examples.html">Qt Charts Examples</a></td><td >Qml Charts Example</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtcharts-index.html">Qt Charts | Commercial or GPLv3</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#running-the-example">Running the Example</a></li>
<li class="level1"><a href="#creating-charts-using-qml">Creating Charts Using QML</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Qml Charts Example</h1>
<span class="subtitle"></span>
<!-- $$$qmlchart-brief -->
<p>This basic demonstration shows how to use the different chart types by using qml.</p>
<!-- @@@qmlchart -->
<!-- $$$qmlchart-description -->
<div class="descr"> <a name="details"></a>
<a name="running-the-example"></a>
<h2 id="running-the-example">Running the Example</h2>
<p>To run the example from Qt Creator, open the <b>Welcome</b> mode and select the example from <b>Examples</b>. For more information, visit Building and Running an Example.</p>
<a name="creating-charts-using-qml"></a>
<h2 id="creating-charts-using-qml">Creating Charts Using QML</h2>
<p>Creating each chart type begins with the creation of a <a href="qml-qtcharts-chartview.html">ChartView</a>.</p>
<p>To create a pie, we use the <a href="qml-qtcharts-pieseries.html">PieSeries</a> API together with a few PieSlices:</p>
<p class="centerAlign"><img src="images/examples_qmlchart1.png" alt="" /></p><pre class="qml">

  ChartView {
      id: chart
      title: "Top-5 car brand shares in Finland"
      anchors.fill: parent
      legend.alignment: Qt.AlignBottom
      antialiasing: true

      PieSeries {
          id: pieSeries
          PieSlice { label: "Volkswagen"; value: 13.5 }
          PieSlice { label: "Toyota"; value: 10.9 }
          PieSlice { label: "Ford"; value: 8.6 }
          PieSlice { label: "Skoda"; value: 8.2 }
          PieSlice { label: "Volvo"; value: 6.8 }
      }
  }

  Component.onCompleted: {
      // You can also manipulate slices dynamically, like append a slice or set a slice exploded
      othersSlice = pieSeries.append("Others", 52.0);
      pieSeries.find("Volkswagen").exploded = true;
  }

</pre>
<p>To create a chart with a line series:</p>
<p class="centerAlign"><img src="images/examples_qmlchart2.png" alt="" /></p><pre class="qml">

  ChartView {
      title: "Line"
      anchors.fill: parent
      antialiasing: true

      LineSeries {
          name: "LineSeries"
          XYPoint { x: 0; y: 0 }
          XYPoint { x: 1.1; y: 2.1 }
          XYPoint { x: 1.9; y: 3.3 }
          XYPoint { x: 2.1; y: 2.1 }
          XYPoint { x: 2.9; y: 4.9 }
          XYPoint { x: 3.4; y: 3.0 }
          XYPoint { x: 4.1; y: 3.3 }
      }
  }

</pre>
<p>And spline series:</p>
<p class="centerAlign"><img src="images/examples_qmlchart3.png" alt="" /></p><pre class="qml">

  ChartView {
      title: "Spline"
      anchors.fill: parent
      antialiasing: true

      SplineSeries {
          name: "SplineSeries"
          XYPoint { x: 0; y: 0.0 }
          XYPoint { x: 1.1; y: 3.2 }
          XYPoint { x: 1.9; y: 2.4 }
          XYPoint { x: 2.1; y: 2.1 }
          XYPoint { x: 2.9; y: 2.6 }
          XYPoint { x: 3.4; y: 2.3 }
          XYPoint { x: 4.1; y: 3.1 }
      }
  }

</pre>
<p>Then we create a chart that illustrates the NHL All-Star player selections by using three area series:</p>
<p class="centerAlign"><img src="images/examples_qmlchart4.png" alt="" /></p><pre class="qml">

  ChartView {
      title: "NHL All-Star Team Players"
      anchors.fill: parent
      antialiasing: true

      // Define x-axis to be used with the series instead of default one
      ValueAxis {
          id: valueAxis
          min: 2000
          max: 2011
          tickCount: 12
          labelFormat: "%.0f"
      }

      AreaSeries {
          name: "Russian"
          axisX: valueAxis
          upperSeries: LineSeries {
              XYPoint { x: 2000; y: 1 }
              XYPoint { x: 2001; y: 1 }
              XYPoint { x: 2002; y: 1 }
              XYPoint { x: 2003; y: 1 }
              XYPoint { x: 2004; y: 1 }
              XYPoint { x: 2005; y: 0 }
              XYPoint { x: 2006; y: 1 }
              XYPoint { x: 2007; y: 1 }
              XYPoint { x: 2008; y: 4 }
              XYPoint { x: 2009; y: 3 }
              XYPoint { x: 2010; y: 2 }
              XYPoint { x: 2011; y: 1 }
          }
      }
      ...

</pre>
<p>Then a couple of scatter series:</p>
<p class="centerAlign"><img src="images/examples_qmlchart5.png" alt="" /></p><pre class="qml">

  ChartView {
      title: "Scatters"
      anchors.fill: parent
      antialiasing: true

      ScatterSeries {
          id: scatter1
          name: "Scatter1"
          XYPoint { x: 1.5; y: 1.5 }
          XYPoint { x: 1.5; y: 1.6 }
          XYPoint { x: 1.57; y: 1.55 }
          XYPoint { x: 1.8; y: 1.8 }
          XYPoint { x: 1.9; y: 1.6 }
          XYPoint { x: 2.1; y: 1.3 }
          XYPoint { x: 2.5; y: 2.1 }
      }

      ScatterSeries {
          name: "Scatter2"
      ...

</pre>
<p>And a few different bar series:</p>
<p class="centerAlign"><img src="images/examples_qmlchart6.png" alt="" /></p><pre class="qml">

  ChartView {
      title: "Bar series"
      anchors.fill: parent
      legend.alignment: Qt.AlignBottom
      antialiasing: true

      BarSeries {
          id: mySeries
          axisX: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] }
          BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] }
          BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] }
          BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] }
      }
  }

</pre>
<p class="centerAlign"><img src="images/examples_qmlchart7.png" alt="" /></p><pre class="qml">

  ChartView {
      title: "Stacked Bar series"
      anchors.fill: parent
      legend.alignment: Qt.AlignBottom
      antialiasing: true

      StackedBarSeries {
          id: mySeries
          axisX: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] }
          BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] }
          BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] }
          BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] }
      }
  }

</pre>
<p class="centerAlign"><img src="images/examples_qmlchart8.png" alt="" /></p><pre class="qml">

  ChartView {
      title: "Percent Bar series"
      anchors.fill: parent
      legend.alignment: Qt.AlignBottom
      antialiasing: true

      PercentBarSeries {
          axisX: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] }
          BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] }
          BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] }
          BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] }
      }
  }

</pre>
<p class="centerAlign"><img src="images/examples_qmlchart9.png" alt="" /></p><pre class="qml">

  ChartView {
      title: "Horizontal Bar series"
      anchors.fill: parent
      legend.alignment: Qt.AlignBottom
      antialiasing: true

      HorizontalBarSeries {
          axisY: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] }
          BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] }
          BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] }
          BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] }
      }
  }

</pre>
<p class="centerAlign"><img src="images/examples_qmlchart10.png" alt="" /></p><pre class="qml">

  ChartView {
      title: "Horizontal Stacked Bar series"
      anchors.fill: parent
      legend.alignment: Qt.AlignBottom
      antialiasing: true

      HorizontalStackedBarSeries {
          axisY: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] }
          BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] }
          BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] }
          BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] }
      }
  }

</pre>
<p class="centerAlign"><img src="images/examples_qmlchart11.png" alt="" /></p><pre class="qml">

  ChartView {
      title: "Horizontal Percent Bar series"
      anchors.fill: parent
      legend.alignment: Qt.AlignBottom
      antialiasing: true

      HorizontalPercentBarSeries {
          axisY: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] }
          BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] }
          BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] }
          BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] }
      }
  }

</pre>
<p>And finally an example demonstrating how to create a donut chart with two pie series:</p>
<p class="centerAlign"><img src="images/examples_qmlchart12.png" alt="" /></p><pre class="qml">

  ChartView {
      id: chart
      title: "Production costs"
      anchors.fill: parent
      legend.visible: false
      antialiasing: true

      PieSeries {
          id: pieOuter
          size: 0.96
          holeSize: 0.7
          PieSlice { id: slice; label: "Alpha"; value: 19511; color: "#99CA53" }
          PieSlice { label: "Epsilon"; value: 11105; color: "#209FDF" }
          PieSlice { label: "Psi"; value: 9352; color: "#F6A625" }
      }

      PieSeries {
          size: 0.7
          id: pieInner
          holeSize: 0.25

          PieSlice { label: "Materials"; value: 10334; color: "#B9DB8A" }
          PieSlice { label: "Employee"; value: 3066; color: "#DCEDC4" }
          PieSlice { label: "Logistics"; value: 6111; color: "#F3F9EB" }

          PieSlice { label: "Materials"; value: 7371; color: "#63BCE9" }
          PieSlice { label: "Employee"; value: 2443; color: "#A6D9F2" }
          PieSlice { label: "Logistics"; value: 1291; color: "#E9F5FC" }

          PieSlice { label: "Materials"; value: 4022; color: "#F9C36C" }
          PieSlice { label: "Employee"; value: 3998; color: "#FCE1B6" }
          PieSlice { label: "Logistics"; value: 1332; color: "#FEF5E7" }
      }
  }

  Component.onCompleted: {
      // Set the common slice properties dynamically for convenience
      for (var i = 0; i < pieOuter.count; i++) {
          pieOuter.at(i).labelPosition = PieSlice.LabelOutside;
          pieOuter.at(i).labelVisible = true;
          pieOuter.at(i).borderWidth = 3;
      }
      for (var i = 0; i < pieInner.count; i++) {
          pieInner.at(i).labelPosition = PieSlice.LabelInsideNormal;
          pieInner.at(i).labelVisible = true;
          pieInner.at(i).borderWidth = 2;
      }
  }

</pre>
<p>Additionally, antialiasing is set with the qml property in Qt Quick 2.</p>
<p>Files:</p>
<ul>
<li><a href="qtcharts-qmlchart-main-cpp.html">qmlchart/main.cpp</a></li>
<li><a href="qtcharts-qmlchart-qml-qmlchart-mainform-ui-qml.html">qmlchart/qml/qmlchart/MainForm.ui.qml</a></li>
<li><a href="qtcharts-qmlchart-qml-qmlchart-view1-qml.html">qmlchart/qml/qmlchart/View1.qml</a></li>
<li><a href="qtcharts-qmlchart-qml-qmlchart-view10-qml.html">qmlchart/qml/qmlchart/View10.qml</a></li>
<li><a href="qtcharts-qmlchart-qml-qmlchart-view11-qml.html">qmlchart/qml/qmlchart/View11.qml</a></li>
<li><a href="qtcharts-qmlchart-qml-qmlchart-view12-qml.html">qmlchart/qml/qmlchart/View12.qml</a></li>
<li><a href="qtcharts-qmlchart-qml-qmlchart-view2-qml.html">qmlchart/qml/qmlchart/View2.qml</a></li>
<li><a href="qtcharts-qmlchart-qml-qmlchart-view3-qml.html">qmlchart/qml/qmlchart/View3.qml</a></li>
<li><a href="qtcharts-qmlchart-qml-qmlchart-view4-qml.html">qmlchart/qml/qmlchart/View4.qml</a></li>
<li><a href="qtcharts-qmlchart-qml-qmlchart-view5-qml.html">qmlchart/qml/qmlchart/View5.qml</a></li>
<li><a href="qtcharts-qmlchart-qml-qmlchart-view6-qml.html">qmlchart/qml/qmlchart/View6.qml</a></li>
<li><a href="qtcharts-qmlchart-qml-qmlchart-view7-qml.html">qmlchart/qml/qmlchart/View7.qml</a></li>
<li><a href="qtcharts-qmlchart-qml-qmlchart-view8-qml.html">qmlchart/qml/qmlchart/View8.qml</a></li>
<li><a href="qtcharts-qmlchart-qml-qmlchart-view9-qml.html">qmlchart/qml/qmlchart/View9.qml</a></li>
<li><a href="qtcharts-qmlchart-qml-qmlchart-main-qml.html">qmlchart/qml/qmlchart/main.qml</a></li>
<li><a href="qtcharts-qmlchart-qmlchart-pro.html">qmlchart/qmlchart.pro</a></li>
<li><a href="qtcharts-qmlchart-resources-qrc.html">qmlchart/resources.qrc</a></li>
</ul>
</div>
<!-- @@@qmlchart -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>