OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2014 Google Inc. All rights reserved. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style |
| 5 * license that can be found in the LICENSE file or at |
| 6 * https://developers.google.com/open-source/licenses/bsd |
| 7 */ |
| 8 |
| 9 library charted.demo.charts.custom_axis; |
| 10 |
| 11 import 'dart:html'; |
| 12 import 'package:charted/charts/charts.dart'; |
| 13 import 'package:charted/core/scales.dart'; |
| 14 |
| 15 List COLUMNS = [ |
| 16 new ChartColumnSpec(label:'Month', type:ChartColumnSpec.TYPE_STRING), |
| 17 new ChartColumnSpec(label:'Precipitation'), |
| 18 new ChartColumnSpec(label:'High Temperature'), |
| 19 new ChartColumnSpec(label:'Low Temperature'), |
| 20 new ChartColumnSpec(label:'Random'), |
| 21 new ChartColumnSpec(label:'Extra1'), |
| 22 new ChartColumnSpec(label:'Extra2'), |
| 23 new ChartColumnSpec(label:'Extra3'), |
| 24 ]; |
| 25 |
| 26 List DATA = [ |
| 27 ['January', 4.50, 27, 46, 1, 20, 23, 1], |
| 28 ['February', 4.61, 60, 28, 10, 15, 45, 23], |
| 29 ['March', 3.26, 32, 49, 100, 4, 34, 1], |
| 30 ['April', 1.46, 63, 49, 30, 34, 89, 3] |
| 31 ]; |
| 32 |
| 33 main() { |
| 34 // Default Chart |
| 35 var series1 = new ChartSeries("one", [1, 3, 2, 6], |
| 36 new StackedBarChartRenderer()), |
| 37 data = new ChartData(COLUMNS, DATA), |
| 38 config = new ChartConfig([series1], [0]), |
| 39 area = new CartesianArea(querySelector('.default'), |
| 40 data, config, autoUpdate:false, useTwoDimensionAxes:false); |
| 41 area.draw(); |
| 42 |
| 43 // Chart with custom measure axis with specific domain on the scale. |
| 44 var series2 = new ChartSeries("one", [1, 3, 2, 6], |
| 45 new StackedBarChartRenderer(), |
| 46 // measureAxisId matches the id later used in registerMeasureAxis(). |
| 47 measureAxisIds: ['fixed_domain']), |
| 48 data2 = new ChartData(COLUMNS, DATA), |
| 49 config2 = new ChartConfig([series2], [0]); |
| 50 |
| 51 // Add custom scale and axis config. |
| 52 var scale = new LinearScale(); |
| 53 scale.domain = [0, 1000]; |
| 54 var axisConfig = new ChartAxisConfig(); |
| 55 axisConfig.title = 'Axis title'; |
| 56 axisConfig.scale = scale; |
| 57 |
| 58 config2.registerMeasureAxis('fixed_domain', axisConfig); |
| 59 var customAxisChart = new CartesianArea(querySelector('.custom-domain'), |
| 60 data2, config2, autoUpdate:false, useTwoDimensionAxes:false); |
| 61 customAxisChart.draw(); |
| 62 |
| 63 // Chart with custom measure axis with specific tick values. |
| 64 var series3 = new ChartSeries("one", [1, 3, 2, 6], |
| 65 new StackedBarChartRenderer(), |
| 66 // measureAxisId matches the id later used in registerMeasureAxis(). |
| 67 measureAxisIds: ['fixed_ticks']), |
| 68 data3 = new ChartData(COLUMNS, DATA), |
| 69 config3 = new ChartConfig([series3], [0]); |
| 70 |
| 71 // Add custom scale and axis config. |
| 72 var scale2 = new LinearScale(); |
| 73 scale2.domain = [0, 300]; |
| 74 var axisConfig2 = new ChartAxisConfig(); |
| 75 axisConfig2.title = 'Axis title'; |
| 76 axisConfig2.scale = scale2; |
| 77 axisConfig2.tickValues = [0, 25, 50, 230, 250]; |
| 78 |
| 79 config3.registerMeasureAxis('fixed_ticks', axisConfig2); |
| 80 var fixedTickValueChart = new CartesianArea(querySelector('.custom-ticks'), |
| 81 data3, config3, autoUpdate:false, useTwoDimensionAxes:false); |
| 82 fixedTickValueChart.draw(); |
| 83 } |
OLD | NEW |