table to piechart and barchart... (Using highchart)
2015-10-22 04:15
483 查看
XXXXX | 1/2015 | 2/2015 |
aa | 11 | 33 |
bb | 55 | 22 |
For example, I have two data points:
x: 1/2015, 2/2015
y: 11, 33
------------------------------------------------------------------------------------------------------------------------------------------
<head runat="server">
<title></title>
<script src="javascript/jquery-1.11.3.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
----------------
javascript:
<script type="text/javascript"> $(function () { var objdata = $("#dgReport tr").not(":first").first(); if (objdata.length) { plotChart(objdata); } }); function dlIndexChange() { var dd = document.getElementById('DropDownList2'); var a = dd.options[dd.selectedIndex].value; var obj = $("#dgReport tr:nth-child(" + (parseInt(a) + 1) + ")"); var header = $("#dgReport tr:first").children().not(':first'); if (obj.length) { plotChart(obj); } } function getRowNumber(obj) { return obj.parents("tr:first")[0].rowIndex; } function plotChart(obj) { var header = $("#dgReport tr:first").children().not(':first'); plotBarChart(obj.closest('tr'), header); plotPieChart(obj.closest('tr'), header); } function plotBarChart(obj, header) { var names = obj.children("td:first").html(); var dataseries = getChartData(obj); var label = getLabelData(header); //var data = toObject(label, dataseries); $('#barchart').highcharts({ chart: { type: 'column' }, title: { text: names + ' Expense Trend' }, xAxis: { categories: label, crosshair: true }, yAxis: { min: 0, title: { text: 'Expense ($)' } }, tooltip: { headerFormat: '<span style="font-size:10px">{point.key}</span><table>', pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' + '<td style="padding:0"><b> ${point.y:.1f} </b></td></tr>', footerFormat: '</table>', shared: true, useHTML: true }, plotOptions: { column: { pointPadding: 0.2, borderWidth: 0 } }, series: [{ name: names, data: dataseries }] }); } function plotPieChart(obj, header) { var names = obj.children("td:first").html(); var dataseries = getChartData(obj); var label = getLabelData(header); var data = toObject(label, dataseries); //var titlepie = 'Tems Trend Pie chart'; // pie chart $('#piechart').highcharts({ chart: { plotBackgroundColor: null, plotBorderWidth: null, plotShadow: false, type: 'pie' }, title: { text: names + ' Expense Trend' }, subtitle: { text: ' by Percentage' }, tooltip: { pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>' }, plotOptions: { pie: { allowPointSelect: true, cursor: 'pointer', dataLabels: { enabled: true, format: '<b>{point.name}</b>: {point.percentage:.1f} %', style: { color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black' } } } }, series: [ { name: names, colorByPoint: true, data: data }] }); } function getChartData(obj) { var arrayObj = new Array(); obj.children("td").not(':first').each(function () { var data = $(this).html().replace("$", ""); arrayObj.push(parseInt(data)); }); return arrayObj; } function getLabelData(obj) { var arrayObj = new Array(); obj.each(function () { var data = $(this).html(); arrayObj.push(data); }); return arrayObj; } // to [[x],[y]] function toObject(arr1, arr2) { var rv = []; for (var i = 0; i < arr1.length; i++) { if (arr1[i] !== undefined) { var obj = '{name: "' + arr1[i] + '", y: ' + arr2[i] + '}'; rv.push(eval("(" + obj + ")")); } } return rv; } </script>
.... not going to put html source code here...
相关文章推荐
- 时空分割的画面--用xcode命令行回忆turbo c
- css中padding、margin属性的区别和详解
- Java中匿名类使用方法总结
- *LeetCode-Count Univalue Subtrees
- Use openCV lib in either Pre-built libraries or yourself build libs
- Leetcode Product of Array Except Self
- UGUI 帧动画插件
- LAMP进阶之路--熟悉Linux
- jdbcTemplate模板的一些方法初学笔记
- mac最常用终端命令
- 遗传基因科普(4):为何人类不能制造DNA分子?
- OpenCV+VS, tell you how it really works
- Leetcode Verify Preorder Sequence in Binary Search Tree
- 基于MATLAB的直方图均衡化
- 几个大牛的技术博客
- 快速堆栈模糊算法
- 快速堆栈模糊算法
- android v7兼容包
- *LeetCode-Verify Preorder Sequence in Binary Search Tree
- Tomcat处理HTTP请求源码分析(上)