图表控件的学习===》hightChart 和 Chartjs的使用
hightChart : 比较旧的图表控件 商业需要授权
Chartjs 免费开源
刚开始使用了下 hightchart 然后参考示例 建了对应的参数配置的类, 也顺利的集合到后台动态传输。 后面感觉要商业授权,还是算了。
半夜4点多起来 看了下chartjs的示例,感觉比hightchart会更简单点,比较好管理,所以就全部看完之后,自己早上又开始重新建了对应的配置类进行测试。
https://code.google.com/archive/p/ichartjs/downloads 下载地址 要下载最新的2.0版本
/// <summary>
/// chartjs的类==》 一定要下载对应的文档
/// </summary>
public class ChartsjsBase:IChartsBase
{
public ChartsjsBase()
{ }
/// <summary>
/// 数据
/// </summary>
public Data data { get; set; }
public Options options { get; set; }
public string ToJson()
{ return JsonHelper.Serialize(this);
}
/// <summary>
/// 可以返回之后 用mvc 的json再转
/// </summary>
/// <returns></returns>
public string ToJsonType()
{
JObject json = new JObject();
json.Add(data);
json.Add(options);
return json.ToString();
}
}
/// <summary>
/// 数据
/// </summary>
public class Data
{
/// <summary>
/// x轴的表示
/// </summary>
public string labels { get; set; }
/// <summary>
/// 数据,数组中的每一个object代表一条线
/// </summary>
public DataSets[] datasets { get; set; }
} /// <summary>
/// 报表数据
/// // 颜色的使用类似于CSS,你也可以使用RGB、HEX或者HSL
// rgba颜色中最后一个值代表透明度
// 填充颜色
/// </summary>
public class DataSets
{
/// <summary>
/// // 填充颜色
/// </summary>
public string fillColor { get; set; }
/// <summary>
/// 线的颜色
/// </summary>
public string strokeColor { get; set; }
/// <summary>
/// 点的填充颜色
/// </summary>
public string pointColor { get;set; }
/// <summary>
/// 点的边线颜色
/// </summary>
public string pointStrokeColor { get; set; }
/// <summary>
/// 与x轴标示对应的数据
/// </summary>
public double[] data { get; set; } } #region 配置 图标
/// <summary>
/// 配置
/// </summary>
public class Options
{
/// <summary>
/// 配置
/// </summary>
public Options()
{
this.animationEasing="easeOutQuart";
this.animation=true;
this.animationSteps=60;
//1
this.bezierCurve=true;
//3
this.datasetFill=true;
this.datasetStroke=true;
this.datasetStrokeWidth=1;
this.onAnimationComplete=null;
//16
this.scaleFontColor=Color.Blue.ToString();
this.scaleFontFamily="Arial";
this.scaleFontStyle="normal";
this.scaleGridLineColor=Color.AliceBlue.ToString();
this.scaleLabel="Unions";
this.scaleLineColor=Color.Black.ToString();
this.scaleFontSize=12;
this.scaleGridLineWidth=1;
this.scaleLineWidth=2;
this.scaleSteps=5;
this.scaleStepWidth=2;
this.scaleOverlay=true;
this.scaleOverride=true;
this.scaleStartValue=0;
this.scaleShowLabels=true;
this.scaleShowGridLines=true;
//3
this.pointDot=true;
this.pointDotRadius=0.5;
this.pointDotStrokeWidth=1;
}
/// <summary>
/// 网格线是否在数据线的上面
/// </summary>
public bool scaleOverlay { get; set; }
/// <summary>
/// 是否用硬编码重写y轴网格线
/// </summary>
public bool scaleOverride { get; set; }
/// <summary>
/// y轴刻度的个数
/// </summary>
public int? scaleSteps { get; set; }
/// <summary>
/// y轴每个刻度的宽度
/// </summary>
public int? scaleStepWidth { get; set; }
/// <summary>
/// 起始值
/// </summary>
public int? scaleStartValue { get; set; }
/// <summary>
/// x y的颜色
/// </summary>
public string scaleLineColor { get; set; }
/// <summary>
/// xy轴的线宽
/// </summary>
public int scaleLineWidth { get; set; } //Boolean - Whether to show labels on the scale
/// <summary>
/// 是否显示y轴的标签
/// </summary>
public bool scaleShowLabels { get; set; } //Interpolated JS string - can access value
/// <summary>
/// .标签显示值
/// </summary>
public string scaleLabel { get;set; } //String - Scale label font declaration for the scale label
/// <summary>
/// 标签的字体 Arial
/// </summary> public string scaleFontFamily { get; set; } //Number - Scale label font size in pixels
/// <summary>
/// 标签字体的大小
/// </summary> public int scaleFontSize { get; set; } //String - Scale label font weight style
/// <summary>
/// 标签字体的样式 normal
/// </summary> public string scaleFontStyle { get;set; } //String - Scale label font colour
/// <summary>
/// #666 标签字体的颜色
/// </summary>
public string scaleFontColor { get; set; } ///Boolean - Whether grid lines are shown across the chart
/// <summary>是否显示网格线
/// </summary>
public bool scaleShowGridLines { get; set; } //String - Colour of the grid lines
/// <summary>
/// 网格线的颜色 : "rgba(0,0,0,.1)",
/// </summary> public string scaleGridLineColor { get; set; } //Number - Width of the grid lines
/// <summary>
/// 网格线的线宽
/// </summary> public int scaleGridLineWidth {get; set; } //Boolean - Whether the line is curved between points
/// <summary>
/// 是否是曲线
/// </summary> public bool bezierCurve { get; set; } //Boolean - Whether to show a dot for each point
/// <summary>
/// 是否显示点
/// </summary> public bool pointDot { get; set; } //Number - Radius of each point dot in pixels
/// <summary>
/// 点的半径
/// </summary> public double pointDotRadius { get; set; } //Number - Pixel width of point dot stroke
/// <summary>
/// 点的线宽
/// </summary> public int pointDotStrokeWidth { get;set; } /// <summary>
/// Boolean - Whether to show a stroke for datasets
/// </summary> public bool datasetStroke { get;set; } //Number - Pixel width of dataset stroke
/// <summary>
/// 数据线的线宽
/// </summary> public int datasetStrokeWidth { get; set; } //Boolean - Whether to fill the dataset with a colour
/// <summary>
/// 数据线是否填充颜色
/// </summary> public bool datasetFill { get; set; } //Boolean - Whether to animate the chart
/// <summary>
/// 是否有动画效果
/// </summary> public bool animation { get; set; } //Number - Number of animation steps
/// <summary>
/// 动画的步数 60
/// </summary> public int animationSteps { get; set; } //String - Animation easing effect
/// <summary>
/// 动画的效果 easeOutQuart
/// </summary> public string animationEasing { get; set; } //Function - Fires when the animation is complete
/// <summary>
/// 动画完成后调用 Function 可以写功能 null
/// </summary>
public string onAnimationComplete { get; set; }
/// <summary>
/// 写到xml文档 26个字段
/// </summary>
/// <param name="doc"></param>
public void WriteToXml(XmlDocument doc)
{
XmlNode root = doc.SelectSingleNode("Settings");
//3
Options.SetNodeValue(doc, root, "animationEasing", this.animationEasing);
Options.SetNodeValue(doc, root, "animation", this.animation.ToString());
Options.SetNodeValue(doc, root, "animationSteps", this.animationSteps.ToString());
//1
Options.SetNodeValue(doc, root, "bezierCurve", this.bezierCurve.ToString());
//3
Options.SetNodeValue(doc, root, "datasetFill", this.datasetFill.ToString());
Options.SetNodeValue(doc, root, "datasetStroke", this.datasetStroke.ToString());
Options.SetNodeValue(doc, root, "datasetStrokeWidth", this.datasetStrokeWidth.ToString());
Options.SetNodeValue(doc, root, "onAnimationComplete", this.onAnimationComplete);
//16
Options.SetNodeValue(doc, root, "scaleFontColor", this.scaleFontColor);
Options.SetNodeValue(doc, root, "scaleFontFamily", this.scaleFontFamily);
Options.SetNodeValue(doc, root, "scaleFontStyle", this.scaleFontStyle);
Options.SetNodeValue(doc, root, "scaleGridLineColor", this.scaleGridLineColor);
Options.SetNodeValue(doc, root, "scaleLabel", this.scaleLabel);
Options.SetNodeValue(doc, root, "scaleLineColor", this.scaleLineColor);
Options.SetNodeValue(doc, root, "scaleFontSize", this.scaleFontSize.ToString());
Options.SetNodeValue(doc, root, "scaleGridLineWidth", this.scaleGridLineWidth.ToString());
Options.SetNodeValue(doc, root, "scaleLineWidth", this.scaleLineWidth.ToString());
Options.SetNodeValue(doc, root, "scaleSteps", this.scaleSteps.ToString());
Options.SetNodeValue(doc, root, "scaleStepWidth", this.scaleStepWidth.ToString());
Options.SetNodeValue(doc, root, "scaleOverlay", this.scaleOverlay.ToString());
Options.SetNodeValue(doc, root, "scaleOverride", this.scaleOverride.ToString());
Options.SetNodeValue(doc, root, "scaleStartValue", this.scaleStartValue.ToString());
Options.SetNodeValue(doc, root, "scaleShowLabels", this.scaleShowLabels.ToString());
Options.SetNodeValue(doc, root, "scaleShowLabels", this.scaleShowGridLines.ToString());
//3
Options.SetNodeValue(doc, root, "pointDot", this.pointDot.ToString());
Options.SetNodeValue(doc, root, "pointDotRadius", this.pointDotRadius.ToString());
Options.SetNodeValue(doc, root, "pointDotStrokeWidth", this.pointDotStrokeWidth.ToString());
} /// <summary>
/// 从xml返回数据
/// </summary>
/// <param name="doc"></param>
/// <returns></returns>
public static Options FromXml(XmlDocument doc)
{
XmlNode xmlNode = doc.SelectSingleNode("Options");
return new Options()
{
animationSteps = int.Parse(xmlNode.SelectSingleNode("animationSteps").InnerText),
animation = bool.Parse(xmlNode.SelectSingleNode("animation").InnerText),
animationEasing = xmlNode.SelectSingleNode("animationEasing").InnerText,
bezierCurve =bool.Parse( xmlNode.SelectSingleNode("animationEasing").InnerText),
datasetFill = bool.Parse(xmlNode.SelectSingleNode("datasetFill").InnerText),
datasetStroke = bool.Parse(xmlNode.SelectSingleNode("datasetStroke").InnerText),
datasetStrokeWidth = int.Parse(xmlNode.SelectSingleNode("datasetStrokeWidth").InnerText),
onAnimationComplete = xmlNode.SelectSingleNode("onAnimationComplete").InnerText,
scaleLineWidth = int.Parse(xmlNode.SelectSingleNode("scaleLineWidth").InnerText),
scaleFontSize = int.Parse(xmlNode.SelectSingleNode("datasetStrokeWidth").InnerText),
scaleOverride = bool.Parse(xmlNode.SelectSingleNode("scaleOverride").InnerText),
scaleFontStyle =(xmlNode.SelectSingleNode("scaleFontStyle").InnerText),
scaleStepWidth = int.Parse(xmlNode.SelectSingleNode("scaleStepWidth").InnerText),
scaleFontColor =(xmlNode.SelectSingleNode("scaleFontColor").InnerText),
scaleOverlay = bool.Parse(xmlNode.SelectSingleNode("scaleOverlay").InnerText),
scaleShowGridLines = bool.Parse(xmlNode.SelectSingleNode("scaleShowGridLines").InnerText),
scaleLabel = (xmlNode.SelectSingleNode("scaleLabel").InnerText),
scaleLineColor = (xmlNode.SelectSingleNode("scaleLineColor").InnerText),
scaleGridLineColor = (xmlNode.SelectSingleNode("scaleGridLineColor").InnerText),
scaleSteps = int.Parse(xmlNode.SelectSingleNode("scaleSteps").InnerText),
scaleGridLineWidth = int.Parse(xmlNode.SelectSingleNode("scaleGridLineWidth").InnerText),
scaleFontFamily =(xmlNode.SelectSingleNode("datasetStrokeWidth").InnerText),
scaleStartValue = int.Parse(xmlNode.SelectSingleNode("scaleStartValue").InnerText),
scaleShowLabels =bool.Parse(xmlNode.SelectSingleNode("scaleShowLabels").InnerText),
pointDotStrokeWidth =int.Parse(xmlNode.SelectSingleNode("pointDotStrokeWidth").InnerText),
pointDotRadius = int.Parse(xmlNode.SelectSingleNode("pointDotRadius").InnerText),
pointDot = bool.Parse(xmlNode.SelectSingleNode("pointDotRadius").InnerText)
};
}
/// <summary>
/// 赋值
/// </summary>
/// <param name="doc"></param>
/// <param name="root"></param>
/// <param name="nodeName"></param>
/// <param name="nodeValue"></param>
private static void SetNodeValue(XmlDocument doc, XmlNode root, string nodeName, string nodeValue)
{
XmlNode xmlNode = root.SelectSingleNode(nodeName);
if (xmlNode == null)
{
xmlNode = doc.CreateElement(nodeName);
root.AppendChild(xmlNode);
}
xmlNode.InnerText = nodeValue;
}
}
#endregion
}
前台调用
出现了
// Provide some basic currying to the user
return data ? fn( data ) : fn;
引用: http://www.chartjs.org/assets/Chart.js
<canvas id="myChart" width="400" height="400"></canvas>
var ctx = $("#myChart").get(0).getContext("2d");
//This will get the first returned node in the jQuery collection.
var myNewChart = new Chart(ctx);
var _data = { 'sss': 'test' };
var options;
var data;
//new Chart(ctx).PolarArea(data, options); 极地地图
$.ajax(
{
url: '@Url.Action("GetChartjsData","Stores")',
type: 'POST',
dataType: 'json',
data: JSON.stringify(_data),
contentType: 'application/json;charset=uft-8',
success:function(datajson) {
if (datajson != null) {
options = datajson.options;
data = datajson.data;
var chartInstance = new Chart(ctx, {
type: 'line',
data: data,
options: {
responsive: false
}
});
}
}
});
图表控件的学习===》hightChart 和 Chartjs的使用的更多相关文章
- echart图表控件配置入门(一)
现在主流的web图表控件主要有hightchart.fusionchart.echart: echart作为百度前端部门近期推出的一个基于html5的免费图表控件,以其丰富图表类型和良好的兼容性速度得 ...
- 图表控件== 百度 echarts的入门学习
花了3天的时间 去学习跟试用之前两款的图表控件 hightcharts(商业,人性化,新手非常方便试用,图表少了点) 跟chartjs==>搭配vue更好 控件,整体而言都还可以. http:/ ...
- 【WPF】 OxyPlot图表控件学习
最近在学习OxyPlot图表控件,一些基本的学习心得,在这里记录一下,方便以后进行查找. 一.引用 OxyPlot控件可以直接在VS的 " Nuget " 里面下载 选择: ...
- ASP.NET Core MVC TagHelper实践HighchartsNET快速图表控件-开源
ASP.NET Core MVC TagHelper最佳实践HighchartsNET快速图表控件支持ASP.NET Core. 曾经在WebForms上写过 HighchartsNET快速图表控件- ...
- HighchartsNET快速图表控件-开源
前言: HighchartsNET快速图表控件,基于Highcharts的asp.net web控件.只需几行代码你就能快速生成一个图表. 从此不再担心图表复杂.简单几行代码就可以搞定,节省大量工作时 ...
- HTML5优秀图表控件
不管是哪个领域的开发,都有机会用到图表来做统计分析,以更直观的表现形式来代替传统的文字.在以前,图表控件主要有使用程序代码生成的静态图片,或者是使用flash实现的图表控件. 在HTML5非常流行的当 ...
- 转:Highcharts图表控件的使用
摘要 Highcharts图表控件是目前使用最为广泛的图表控件.本文将从零开始逐步为你介绍Highcharts图表控件.通过本文,你将学会如何配置Highcharts以及动态生成Highchart图表 ...
- .net chart(图表)控件的使用-System.Windows.Forms.DataVisualization.dll
这个案例指在介绍微软这套免费又功能强大的图表控件Microsoft Chart Controls for Microsoft .NET Framework 3.5,通过它,可让您的项目及报表,轻松套用 ...
- C#图表控件ZedGraph使用
最近从java转到C#下开发PC端的桌面程序,之前也尝试用java GUI写桌面程序,发现java写桌面程序还是诸多不便变,虽然最后也写出来了,但是决心还是另起平台,有了一定的java基础,来学习C# ...
随机推荐
- 最有效地优化 Microsoft SQL Server 的性能
为了最有效地优化 Microsoft SQL Server 的性能,您必须明确当情况不断变化时,性能将在哪些方面得到最大程度的改进,并集中分析这些方面.否则,在这些问题上您可能花费大量的时间和精力 ...
- LINQ查询操作符之First、FirstOrDefault、Last、LastOrDefault、ElementAt、ElementAtOrDefault、Contains、Any、All、Coun
·First - 返回集合中的第一个元素:不延迟 ·FirstOrDefault - 返回集合中的第一个元素(如果没有则返回默认值):不延迟 ·Last - 返回集合中的最后一个元素:不延迟 ·Las ...
- @synthesize vs. @dynamic
@synthesize will generate getter and setter methods and corresponding instance variable for your pro ...
- pickle与shelve
pickle Example 写入文件 import pickle integers = [1, 2, 3, 4, 5] with open('pickle-example.p', 'wb') as ...
- UseFul Collection
....... 啦啦啦,test... http://bbs.csdn.net/topics/380175613 http://zhidao.baidu.com/question/580940892. ...
- jQuery 效果 —— 滑动
jQuery 效果 -- 滑动 1.向下滑动元素 (1)使用slideDown()方法可以用于向下滑动元素 $("button").click(function(){ $(&quo ...
- Bootstrap_进度条
<!--基本进度条--> <div class="progress"> <div %</div> </div> <!-- ...
- Linux文本流
Linux文本流 作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 文本流 文件用于数据的存储,相当于一个个存储数据的房子.我们 ...
- A replacement solution to using Google Drive in Ubuntu
Grive2 Get dependencies You need to get the dependency libraries along with their development (-dev ...
- os.environ()
---------2016-5-9 18:56:39-- source:OS.ENVIRON()详解