1.0.3 • Published 3 years ago

jw-f2 v1.0.3

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

npm.io

jw-f2

a light chart component based on native @antv/f2 for wechat-miniprogram >> Github

Install

  1. Install package: npm install jw-f2
  2. Build package:
    • tick detials -> Use NPM module
    • build npm: tools -> build npm

Attributes

AttributeDescriptionCompulsoryTypeDefault
idid of canvasNoString__jw-f2-canvas

Events

AttributeDescriptionCompulsoryTypeDefault
onRenderrender chart functionYesFunction-

Usage

Use as a custom component

BasicRadarChart component 1. index.js

Component({
  properties: {
    chartData: {
      type: Object,
      value: {}
    }
  },
  data: {
    chartId: '__jw-basic-radar'
  },
  methods: {
    renderChart(e) {
      const {F2, config, that} = e.detail;
      if(!F2 || !config || !that) return;
      const chart = new F2.Chart(config);
      chart.coord('polar');
      chart.source(this.properties.chartData, {
        score: {
          min: 0,
          max: 5,
          nice: false,
          tickInterval: 1
        }
      });
      chart.axis('score', {
        label: false,
        line: null,
        tickLine: null,
        grid: {
          stroke: '#999',
          line: {
            style: {
              lineDash: null
            }
          }
        }
      });
      chart.axis('stack', {
        line: null,
        tickLine: null,
        grid: {
          lineDash: null,
          stroke: '#999'
        }
      });
      chart.line().position('stack*score').color('type').size(2);;
      chart.point().position('stack*score').color('type').size(4)
        .style({
          stroke: '#fff',
          lineWidth: 1
        });
      chart.render();
      that.chart = chart;
      that.canvasEl = chart.get('el');
    }
  }
})
  1. index.json
{
  "component": true,
  "usingComponents": {
    "jw-f2": "jw-f2"
  }
}
  1. index.wxml
<view class="chart-container">
  <jw-f2 bindonRender="renderChart" id="{{chartId}}"/>
</view>
  1. index.wxss
.chart-container {
  width: 100%;
  height: 500rpx;
}

Use in a page

BasicRadarChart in a page 1. index.js

Page({
  data: {
    chartId: '__jw-basic-radar',
    chartData: []
  },
  ... //get your chart data
  methods: {
    renderChart(e) {
      const {F2, config, that} = e.detail;
      if(!F2 || !config || !that) return;
      const chart = new F2.Chart(config);
      chart.coord('polar');
      chart.source(this.properties.chartData, {
        score: {
          min: 0,
          max: 5,
          nice: false,
          tickInterval: 1
        }
      });
      chart.axis('score', {
        label: false,
        line: null,
        tickLine: null,
        grid: {
          stroke: '#999',
          line: {
            style: {
              lineDash: null
            }
          }
        }
      });
      chart.axis('stack', {
        line: null,
        tickLine: null,
        grid: {
          lineDash: null,
          stroke: '#999'
        }
      });
      chart.line().position('stack*score').color('type').size(2);;
      chart.point().position('stack*score').color('type').size(4)
        .style({
          stroke: '#fff',
          lineWidth: 1
        });
      chart.render();
      that.chart = chart;
      that.canvasEl = chart.get('el');
    }
  }
})
  1. index.json
{
  "usingComponents": {
    "jw-f2": "jw-f2"
  }
}
  1. index.wxml
<view class="chart-container">
  <jw-f2 bindonRender="renderChart" id="{{chartId}}"/>
</view>
  1. index.wxss
.chart-container {
  width: 100%;
  height: 500rpx;
}

A list of examples >> jw-f2-examples

Support this project

  • Buy me a coffee

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago