QtChart实现坐标(y)轴不等分

翻看QtChart的例子的时候,发现了一个QCategoryAxis(QML中是CategoryAxis),允许自已定义范围的长度。这样就可以实现坐标轴不等分。
需要QtCharts 2.2

QtChart实现坐标(y)轴不等分_第1张图片

代码如下(QML方式)

ChartView {
        id : chartview1
          width: 700
          height: 300

          theme: ChartView.ChartThemeBlueCerulean
          antialiasing: true
          margins.top: 0
          margins.bottom: 0
          margins.left : 0
          margins.right:0

          ValueAxis {
                   id: xAxis
                   min: 0
                   max: 3000
               }
          ValueAxis {
                   id: yAxis1
                   min: 0
                   max: 12
               }
            plotAreaColor : "green"
          LineSeries {
              id : lineseries1
              axisX : xAxis;
              axisY: CategoryAxis {
                  min: 0
                  max: 30
                  CategoryRange {
                      label: "critical"
                      endValue: 2
                  }
                  CategoryRange {
                      label: "low"
                      endValue: 4
                  }
                  CategoryRange {
                      label: "normal"
                      endValue: 7
                  }
                  CategoryRange {
                      label: "high"
                      endValue: 15
                  }
                  CategoryRange {
                      label: "extremely high"
                      endValue: 30
                  }
              }
              name: "LineSeries"
              pointsVisible: true
              XYPoint { x: 0; y: 4.3 }
               XYPoint { x: 200; y: 10 }
               XYPoint { x: 400; y: 4.7 }
               XYPoint { x: 600; y:  16}
               XYPoint { x: 800; y: 28 }

          }
      }

问题:显示的坐标轴上的标签位置不能指定,在中间位置。

你可能感兴趣的:(Qt,qml,QtChart)