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=270;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=250;bottom=410;autohscroll=false;autovscroll=false;bgcolor=16777215;clipBk=false;db=1;dl=1;dt=1;notify=1;z=1};
scrollbar={cls="scrollbar";left=250;top=10;right=270;bottom=410;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",
scale =1
},
{ // 文本
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 cplus = godking.customPlus(winform.plus2,itemModel,itemList,{
itemWidth=150, /*项目最小宽度,为0时根据colnum自动计算,所以不能与colnum同时=0*/
itemHeight=100, /*项目最小高度,为0时根据rownum自动计算,所以不能与rownum同时=0*/
autoSizeWidth=true, /*为true则自动将项目总宽度拉伸填满plus宽度,每个项目宽度不小于itemWidth*/
autoSizeHeight=true, /*为true则自动将项目总高度拉伸填满plus高度,每个项目高度不小于itemHeight*/
rownum=0, /*项目行数,为0时根据itemHeight自动计算,所以不能与itemHeight同时=0*/
colnum=2, /*项目列数,为0时根据itemWidth自动计算,所以不能与itemWidth同时=0*/
padLeft=0, /*plus左边空白距离*/
padTop=0, /*plus顶边空白距离*/
padRight=0, /*plus右边空白距离*/
padBottom=0, /*plus底边空白距离*/
autoFit=false, /*是否自动调整plus组件宽度或高度(其中之一),保证能刚好显示全部行或列*/
/*当 itemHeight>0 且 colnum>0 且 rownum=0 时,自动调整plus高度,以能显示全部行*/
/*当 itemWidth>0 且 rownum>0 且 colnum=0 时,自动调整plus宽度,以能显示全部列*/
vertical=false, /*是否将项目设置为竖向排列,行滚动方向设置为横向*/
bkcolor=0xFFFFFFFF, /*背景颜色*/
bkimg=null, /*背景图像*/
})
cplus.bindScrollbar(winform.scrollbar)
winform.adjust = function( cx,cy,wParam ) {
cplus.init();
cplus.bindScrollbar(winform.scrollbar);
};
cplus.onClick = function(itemIndex/*项目索引*/,elemIndex/*元素索引*/,elemID/*元素id*/,elemName/*元素name*/,pageIndex/*当前页项目索引*/){
chuli(itemIndex);
}
winform.show();
win.loopMessage();
更多推荐
已为社区贡献2条内容
所有评论(0)