draw method

  1. @override
void draw(
  1. Canvas canvas,
  2. ChartsState state
)

Implementation

@override
void draw(Canvas canvas, ChartsState state) {
  ChartDimensionCoordinateState layout = state.layout as ChartDimensionCoordinateState;
  //offset.dx 滚动偏移  (src.zoom - 1) * (src.size.width / 2) 缩放
  double left = layout.left;
  left = layout.transform.withXScroll(left);
  double bottom = layout.size.height - layout.bottom;

  //遍历数据 处理数据信息
  for (T itemData in data) {
    num xvs = position.call(itemData);
    num yvs = value.call(itemData);
    double xPo = xvs * layout.xAxis.density + left;
    double yPo = bottom - layout.yAxis[yAxisPosition].getHeight(yvs);
    yPo = layout.transform.withYScroll(yPo);
    ScatterStyle sy = style.call(itemData);
    //最后画点
    if (sy.radius > 0) {
      _dotPaint.style = PaintingStyle.fill;
      Color color = sy.color;
      canvas.drawCircle(Offset(xPo, yPo), sy.radius, _dotPaint..color = color);
    }
  }
}