1 简介
- UIBarChart
- UIBarChartEx
- UIDoughnutChat
- UILineChart
- UIPieChart
2 UIBarChart
- 柱状图,与Echart的用法类似
- 可以修改主题颜色
- barChart.ChartStyleType = UIChartStyleType.Default;//默认颜色
- barChart.ChartStyleType = UIChartStyleType.Plain; // Plain型
- BarChart.ChartStyleType = UIChartStyleType.Dark; // 黑色
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/288460027a3dddda09e2829c099b83ef.png)
- 下面提供一个使用的案例
- 我们其实只关注以下几件事
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace BarChartLearn
{
public partial class Form1 : Form
{
private UIBarOption option;
public Form1()
{
InitializeComponent();
option = new UIBarOption();
option.Title = new UITitle();
option.Title.Text = "SunnyUI";
option.Title.SubText = "BarChart";
option.Legend = new UILegend();
option.Legend.Orient = UIOrient.Horizontal;
option.Legend.Top = UITopAlignment.Top;
option.Legend.Left = UILeftAlignment.Left;
option.Legend.AddData("Bar1");
option.Legend.AddData("Bar2");
UIBarSeries series = new UIBarSeries();
series.Name = "Bar1";
series.AddData(1.1);
series.AddData(1.1);
series.AddData(1.1);
series.AddData(1.1);
series.AddData(1.1);
option.Series.Add(series);
series = new UIBarSeries();
series.Name = "Bar2";
series.AddData(1.1);
series.AddData(1.1);
series.AddData(1.1);
series.AddData(1.1);
series.AddData(1.1);
option.Series.Add(series);
option.XAxis.Data.Add("Mon");
option.XAxis.Data.Add("Tue");
option.XAxis.Data.Add("Wed");
option.XAxis.Data.Add("Thu");
option.XAxis.Data.Add("Fri");
option.ToolTip.Visible = true;
option.YAxis.Scale = true;
option.XAxis.Name = "日期";
option.YAxis.Name = "数值";
option.YAxisScaleLines.Add(new UIScaleLine() { Color = Color.Red, Name = "上限", Value = 12 });
option.YAxisScaleLines.Add(new UIScaleLine() { Color = Color.Gold, Name = "下限", Value = -20 });
BarChart.SetOption(option);
}
private void bt1_Click(object sender, EventArgs e)
{
}
private void bt2_Click(object sender, EventArgs e)
{
UIBarSeries serie = option.Series[0];
List<double> datasList = serie.Data;
double[] datas = datasList.ToArray();
serie.Clear();
for (int i=0;i<datas.Length;i++)
{
datas[i] += (i+1)*1.1;
serie.AddData(datas[i]);
}
option.Series[0] = serie;
BarChart.SetOption(option);
}
}
}
3 LineChart
- 画折线图
- 可以修改主题颜色
- lineChart.ChartStyleType = UIChartStyleType.Default;//默认颜色
- lineChart.ChartStyleType = UIChartStyleType.Plain; // Plain型
- lineChart.ChartStyleType = UIChartStyleType.Dark; // 黑色
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/279404edce1d0db9f3872f767b8aeda5.png)
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace LineChartLearn
{
public partial class Form1 : Form
{
private UILineOption option;
public Form1()
{
InitializeComponent();
option = new UILineOption();
option.ToolTip.Visible = true;
option.Title = new UITitle();
option.Title.Text = "SunnyUI";
option.Title.SubText = "LineChart";
option.XAxisType = UIAxisType.Value;
var series = option.AddSeries(new UILineSeries("Line1"));
float[] x = { 1, 2, 3, 4, 5, 6, 7 };
float[] y = { 2, 4, 6, 8, 10, 12, 14 };
for(int i=0;i<x.Length;i++)
{
series.Add(x[i], y[i]);
}
series.Symbol = UILinePointSymbol.Square;
series.SymbolSize = 4;
series.SymbolLineWidth = 2;
series.SymbolColor = Color.Red;
series = option.AddSeries(new UILineSeries("Line2", Color.Lime));
float[] x2 = { 1, 2, 3, 4, 5, 6, 7 };
float[] y2 = { 3, 6, 9, 12, 15, 18, 21 };
for (int i = 0; i < x.Length; i++)
{
series.Add(x2[i], y2[i]);
}
series.Symbol = UILinePointSymbol.Star;
series.SymbolSize = 4;
series.SymbolLineWidth = 2;
series.SymbolColor = Color.Red;
series.Smooth = true;
option.GreaterWarningArea = new UILineWarningArea(3.5);
option.LessWarningArea = new UILineWarningArea(2.2, Color.Gold);
option.YAxisScaleLines.Add(new UIScaleLine() { Color = Color.Red, Name = "上限", Value = 3.5 });
option.YAxisScaleLines.Add(new UIScaleLine() { Color = Color.Gold, Name = "下限", Value = 2.2 });
option.XAxis.Name = "事件";
option.YAxis.Name = "数值";
option.XAxis.AxisLabel.DateTimeFormat = DateTimeEx.DateTimeFormat;
option.XAxisScaleLines.Add(new UIScaleLine() { Color = Color.Red, Name = "x上界", Value = 50 });
option.XAxisScaleLines.Add(new UIScaleLine() { Color = Color.Red, Name = "x下界", Value = -50 });
LineChart.SetOption(option);
}
private void uiButton1_Click(object sender, EventArgs e)
{
UILineSeries serie = option.Series["Line1"];
for (int i=0;i<5;i++)
{
double newX = serie.XData[serie.XData.Count - 1] *1.5;
double newY = serie.XData[serie.YData.Count - 1] * 1.5;
serie.Add(newX, newY);
}
option.Series["Line1"] = serie;
LineChart.SetOption(option);
}
}
}