aardio - 库scottPlot图表控件库

Posted 卢光庆

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了aardio - 库scottPlot图表控件库相关的知识,希望对你有一定的参考价值。

ScottPlot是个非常不错的基于C# 的图表控件库,开源免费,官方的文档和例程也比较丰富,学起来比较容易。

封装C#库,我也是第一次尝试,目前还有某些功能不完善,以后慢慢改进。

顺便用 customPlus库 + scottPlot库 做了一个演示程序,简单演示一句代码添加图形,效果如下:

演示程序代码如下:

import win.ui;
import godking.customPlus
import godking.scottPlot
/*DSG*/
var winform = win.form(text="scottPlot图表控件库演示 by 光庆";right=759;bottom=419)
winform.add(
custom=cls="custom";text="自定义控件";left=150;top=10;right=750;bottom=410;bgcolor=16777215;db=1;dl=1;dr=1;dt=1;z=3;
plus2=cls="plus";left=10;top=10;right=130;bottom=410;autohscroll=false;autovscroll=false;clipBk=false;db=1;dl=1;dt=1;notify=1;z=1;
scrollbar=cls="scrollbar";left=130;top=10;right=150;bottom=420;db=1;dl=1;dt=1;z=2
)
/**/

var chart = godking.scottPlot( winform.custom );
var xs = 1,2,3,4,5,6,7,8,9,10;
var xs2 = 1,1.2,3.4,4,5.6,6,7,7.8,9.5,10;
var labels = "X1","X2","X3","X4","X5","X6","X7","X8","X9","X10";
var ys = 30,80,40,70,10,90,60,55,70,52;
var ys2 = 50,90,60,80,40,120,70,95,80,92;
var plots = "注释","箭头","轴线","柱状图","标注线","气泡图","克利夫兰点图","鸡冠花图","十字辅助线","误差线",
				"填充曲线1","填充曲线2","填充曲线3","填充上下色曲线","热图","水平线","水平填充区域","图片","线","棒棒糖",
				"标记图形","可拖动的标记图形","饼形图","点","多边形","雷达图","径向仪表图","比例尺","散点图","散点图(纯线)",
				"散点图(纯点)","散点阶梯图","信号图","信号图XY","文本","气泡提示","垂直线","垂直填充区域";
var chuli = function(index,getimg)
	chart.Reset();
	var plot;
	if getimg plot = godking.scottPlot.plot(600,400);
	else plot = chart.plot();
	plot.Title("scottPlot图表控件库演示("++plots[index]++") by 光庆",true,0xFFFF0000,16,"宋体");
	plot.XLabel("X坐标轴");
	plot.YLabel("Y坐标轴");
	plot.Layout( , , , 30,10 );
	select(index) 
		case 1 plot.AddAnnotation( '这里是一段注释文本\\n像素坐标为50,50\\n始终会显示在图表的这个位置', 50, 50 );
		case 2 plot.AddArrow( 10,10,0,0,5,0xFFFF0000 );
		case 3 plot.AddAxis( 0, 2, plots[index], 0xFFFF0000);
		case 4 plot.AddBar( ys, xs, 0xFFFF0000 );
		case 5 plot.AddBracket( 0,0,10,10, plots[index] );
		case 6 plot.AddBubblePlot( xs,ys,30,0xFFFF0000,2,0xFF00FFFF );
		case 7 plot.AddClevelandDot( ys, ys2, xs );
		case 8 plot.AddCoxcomb( ys, false );
		case 9 plot.AddCrosshair( 5, 5 );
		case 10 plot.AddErrorBars( xs, ys, 1,1,1,1,1,1,1,1,1,1, 0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3, 1,1,1,1,1,1,1,1,1,1, 2,2,2,2,2,2,2,2,2,2,0xFF0000FF,5 );
		case 11 plot.AddFill(xs,ys,50,0xFF00FF00);
		case 12 plot.AddFill(xs,ys,ys2,0xFF00FF00);
		case 13 plot.AddFill(xs,ys,xs2,ys2,0xFF00FF00);
		case 14 plot.AddFillAboveAndBelow( xs,ys,50,0xFFFF0000,0xFF0000FF );
		case 15 plot.AddHeatmap( ys,ys2,xs,null,false );
		case 16 plot.AddHorizontalLine( 0, 0xFF000FF0, 1, ScottPlot.LineStyle.Dash, plots[index] );
		case 17 plot.AddHorizontalSpan(0, 1, 0xFFFF0000, plots[index] );
		case 18 plot.AddImage( DataGen.SampleImage() , 0, 0, 0, 1, 0 );
		case 19 plot.AddLine(0, 0, 100, 100, 0xFF0000FF, 30 );
		case 20 plot.AddLollipop( ys, xs, 0xFFFF0000 );
		case 21 plot.AddMarker( 0,0,ScottPlot.MarkerShape.filledDiamond,10,0xFFFF0000,plots[index] );
		case 22 plot.AddMarkerDraggable( 0,0,ScottPlot.MarkerShape.filledTriangleDown,10,0xFFFF0000,plots[index] );
		case 23 plot.AddPie( ys, false );
		case 24 plot.AddPoint( 0,0,0xFF00FF00,10,ScottPlot.MarkerShape.filledCircle,plots[index]) ;
		case 25 plot.AddPolygon( xs, ys, 0xFFFF0000, 5, 0xFF0000FF );
		case 26 plot.AddRadar( ys,ys2, false, ,false );
		case 27 plot.AddRadialGauge( ys, false)
		case 28 plot.AddScaleBar( 10,10,"宽度","高度" );
		case 29 plot.AddScatter( xs, ys, 0xFFFF0000, 1, 5, ScottPlot.MarkerShape.filledCircle, ScottPlot.LineStyle.Solid, plots[index] );
		case 30 plot.AddScatterLines( xs, ys, 0xFF00FF00, 1, ScottPlot.LineStyle.Solid, plots[index] );
		case 31 plot.AddScatterPoints( xs, ys, 0xFF0000FF, 5, ScottPlot.MarkerShape.filledCircle, plots[index] );
		case 32 plot.AddScatterStep(  xs, ys, 0xFFFF0000, 1, plots[index] );
		case 33 plot.AddSignal( ys, 1, 0xFF0000FF, plots[index] );
		case 34 plot.AddSignalXY( xs2,ys, 0xFFFF0000, plots[index] );
		case 35 plot.AddText( '在X/Y坐标处显示文本\\n不随图形缩放。' ,0 ,0 ,14 ,0xFFFF0000 );
		case 36 plot.AddTooltip( "气泡提示" ,0 ,0 );
		case 37 plot.AddVerticalLine( 0, 0xFFFF0000, 1, ScottPlot.LineStyle.Solid, plots[index] );
		case 38 plot.AddVerticalSpan(0, 100, 0xFFFF0000, plots[index]);
	
	plot.Legend(true,ScottPlot.Alignment.LowerRight);
	plot.XTicks( xs,labels);
	if getimg return plot.GetImageBytes(false,1); 
	else chart.Refresh(false /*低质量显示*/, true/*正在渲染则跳过*/);

var itemModel = 
	   // 矩形区域
		type="rect",  // 类型:rect
		rectf=x=1;y=1;width=-1;height=-1,  
		name="项目背景色",
		click=true; 
		fillcolor=16#FF7388C1,                // 正常状态下,填充颜色
		itemselectedfillcolor=16#FFEC870E,    // 项目选中时,填充颜色
	,
	   // 图像
		type="img",  // 类型:img
		rectf=x=3;y=3;width=-3;height=-23, 
		name="pic",
	,
	   // 文本
		type="text",  // 类型:text
		rectf=x=0;y=-23;width=0;height=23,  //  文本范围。负数表示距离项目右边的距离。
		name="text",
    	align=1,        // 文本水平对齐方式。0、(近端)左对齐  1、居中  2、(远端)右对齐
    	valign=1,       // 文本垂直对齐方式。0、(近端)顶对齐  1、居中  2、(远端)底对齐
 		font=name="宋体",h=12,color=0xFFFFFFFF,  // 正常状态下字体
	

var itemList = 
for(i=1;#plots;1)
	table.push(itemList,pic=chuli(i,true);text=plots[i])	

var  c = godking.customPlus(winform.plus2,
		itemWidth=150,	/*项目宽度*/
		itemHeight=100,	/*项目高度*/
		autoSizeRow=false,	/*自动根据项目行数及plus高度调整项目高度*/
		autoSizeCol=true,	/*自动根据项目列数及plus宽度调整项目宽度*/
		colnum=1, 	/*项目列数,为0则根据项目宽度和plus宽度自动计算*/
		rownum=0, 	/*项目行数,为0则根据项目高度和plus高度自动计算*/
		padLeft=0,	/*plus左边空白距离*/
		padTop=0,	/*plus顶边空白距离*/
		padRight=0,	/*plus右边空白距离*/
		padBottom=0	/*plus底边空白距离*/
		,itemModel,itemList);
winform.scrollbar.setRange(1,#itemList-c.pageRowCount+1)
winform.scrollbar.oncommand = function(id,event,pos) 
	if( event == 0x8/*_SB_ENDSCROLL*/ ) 
		c.toItem(winform.scrollbar.pos);
	 
	else 
		if( event == 0x0/*_SB_LINEUP*/ )
			winform.scrollbar.pos -= 1
		
		elseif( event == 0x1/*_SB_LINEDOWN*/ )
			winform.scrollbar.pos += 1
		
		elseif( event ==0x5/*_SB_THUMBTRACK*/)  
			winform.scrollbar.pos = pos; //滚动条要存储新刻度
		 
		c.toItem(winform.scrollbar.pos);
	

winform.adjust = function( cx,cy,wParam ) 
	c.init();
	winform.scrollbar.setRange(1,#itemList-c.pageRowCount+1)
;
c.onClick = function(itemIndex/*项目索引*/,elemIndex/*元素索引*/,elemID/*元素id*/,elemName/*元素name*/,pageIndex/*当前页项目索引*/)
		chuli(itemIndex)
	
winform.plus2.onMouseWheel = function(flags,delta,lParam)
	winform.scrollbar.oncommand(0,5,winform.scrollbar.pos-delta/120);

winform.show();
win.loopMessage();

以上是关于aardio - 库scottPlot图表控件库的主要内容,如果未能解决你的问题,请参考以下文章

.NET 开源免费图表组件库,Winform,WPF 通用

C# ScottPlot 绘图控件 源码阅读心得体会

AARDIO 动态添加控件

aardio为啥不火

aardio窗体半透明文字不透明

aardio - 虚标库全新升级,支持图片系列专题