<script> // Get main canvas and cursor canvas in the page // mainCanvas is used to draw the main image // cursorCanvas used to draw a cross cursor const mainCanvas = document.getElementById('myChart') const mainCtx = mainCanvas.getContext('2d') const cursorCanvas = document.getElementById('cursorChart') const cursorCtx = cursorCanvas.getContext('2d')
// Set the configuration of the drawing and pass in the mainCanvas and cursorCanvas for initialization const syscfg = { scale: window.devicePixelRatio, axisPlatform: 'web', // 'phone' | 'web' mainCanvas: { canvas: mainCanvas, context: mainCtx }, cursorCanvas: { canvas: cursorCanvas, context: cursorCtx } } // Create a single stock instance of Chart const Chart = ClChart.createSingleChart(syscfg)
// Clear canvas, and data Chart.clear() const code = 'SH000001' // data initialization // Initialize the current transaction date Chart.initData(20180413, ClChart.DEF_DATA.STOCK_TRADETIME) // Initialize the stock information, the specific field configuration can view the data layer, the definition of various data structures Chart.setData('INFO', ClChart.DEF_DATA.FIELD_INFO, getMockData(code, 'INFO')) Chart.setData('MIN', ClChart.DEF_DATA.FIELD_MIN, getMockData(code, 'MIN')) Chart.setData('TICK', ClChart.DEF_DATA.FIELD_TICK, getMockData(code, 'TICK')) Chart.setData('NOW', ClChart.DEF_DATA.FIELD_NOW, getMockData(code, 'NOW')) // Configure the size of each area of the canvas // The height of the main map let mainHeight = canvas.height * 2 / 3 let mainWidth = canvas.width // Set the canvas area layout const mainLayoutCfg = { layout: ClChart.DEF_CHART.CHART_LAYOUT, config: ClChart.DEF_CHART.CHART_NOW, rectMain: { left: 0, top: 0, width: mainWidth, height: mainHeight } } const mainChart = Chart.createChart('MIN', 'CHART.LINE', mainLayoutCfg, function (result) {}) Chart.bindData(mainChart, 'MIN')
const volumeLoyoutCfg = { layout: ClChart.DEF_CHART.CHART_LAYOUT, config: ClChart.DEF_CHART.CHART_NOWVOL, rectMain: { left: 0, top: mainHeight, width: mainWidth, height: canvas.height - mainHeight } } const volumeChart = Chart.createChart('MINNOW', 'CHART.LINE', volumeLoyoutCfg, function (result) {}) Chart.bindData(volumeChart, 'MIN') // Perform drawing Chart.onPaint() </script>
|