ScottPlot.NET 条形图

条形图快速入门

条形图可以从一系列值中添加。

// add bars
double[] values = { 5, 10, 7, 13 };
WpfPlot1.Plot.Add.Bars(values);

// tell the plot to autoscale with no padding beneath the bars
WpfPlot1.Plot.Axes.Margins(bottom: 0);


WpfPlot1.Refresh();

条形图图例

条形集合可以作为单个项显示在图例中。

double[] xs1 = { 1, 2, 3, 4 };
double[] ys1 = { 5, 10, 7, 13 };
var bars1 = WpfPlot1.Plot.Add.Bars(xs1, ys1);
bars1.LegendText = "Alpha";

double[] xs2 = { 6, 7, 8, 9 };
double[] ys2 = { 7, 12, 9, 15 };
var bars2 = WpfPlot1.Plot.Add.Bars(xs2, ys2);
bars2.LegendText = "Beta";

WpfPlot1.Plot.ShowLegend(Alignment.UpperLeft);
WpfPlot1.Plot.Axes.Margins(bottom: 0);


WpfPlot1.Refresh();

带值标签的条形图

将 bars 的属性设置为在每个 bar 上方显示文本。

double[] values = { 5, 10, 7, 13 };
var barPlot = WpfPlot1.Plot.Add.Bars(values);

// define the content of labels
foreach (var bar in barPlot.Bars)
{
    bar.Label = bar.Value.ToString();
}

// customize label style
barPlot.ValueLabelStyle.Bold = true;
barPlot.ValueLabelStyle.FontSize = 18;

WpfPlot1.Plot.Axes.Margins(bottom: 0, top: .2);


WpfPlot1.Refresh();

带值标签的条形图(水平)

将 bars 的属性设置为在每个条形的旁边(左侧或右侧)显示文本。

 
double[] values = { -20, 10, 7, 13 };

// set the label for each bar
var barPlot = WpfPlot1.Plot.Add.Bars(values);
foreach (var bar in barPlot.Bars)
{
    bar.Label = "Label " + bar.Value.ToString();
}

// customize label style
barPlot.ValueLabelStyle.Bold = true;
barPlot.ValueLabelStyle.FontSize = 18;
barPlot.Horizontal = true;

// add extra margin to account for label
WpfPlot1.Plot.Axes.SetLimitsX(-45, 35);
WpfPlot1.Plot.Add.VerticalLine(0, 1, Colors.Black);


WpfPlot1.Refresh();

棒材定位

每个条形的确切位置和大小可以自定义。

ScottPlot.Bar[] bars =
{
    new() { Position = 1, Value = 5, ValueBase = 3, FillColor = Colors.Red },
    new() { Position = 2, Value = 7, ValueBase = 0, FillColor = Colors.Blue },
    new() { Position = 4, Value = 3, ValueBase = 2, FillColor = Colors.Green },
};

WpfPlot1.Plot.Add.Bars(bars);


WpfPlot1.Refresh();

有误差的柱形

条形可以有误差线。

ScottPlot.Bar[] bars =
{
    new() { Position = 1, Value = 5, Error = 1, FillColor = Colors.Red },
    new() { Position = 2, Value = 7, Error = 2, FillColor = Colors.Orange },
    new() { Position = 3, Value = 6, Error = 1, FillColor = Colors.Green },
    new() { Position = 4, Value = 8, Error = 2, FillColor = Colors.Blue },
};

WpfPlot1.Plot.Add.Bars(bars);

// tell the plot to autoscale with no padding beneath the bars
WpfPlot1.Plot.Axes.Margins(bottom: 0);


WpfPlot1.Refresh();

带有标记即时报价的柱形

可以通过手动指定轴刻度线位置和标签来标记条形。

WpfPlot1.Plot.Add.Bar(position: 1, value: 5, error: 1);
WpfPlot1.Plot.Add.Bar(position: 2, value: 7, error: 2);
WpfPlot1.Plot.Add.Bar(position: 3, value: 6, error: 1);
WpfPlot1.Plot.Add.Bar(position: 4, value: 8, error: 2);

Tick[] ticks =
{
    new(1, "Apple"),
    new(2, "Orange"),
    new(3, "Pear"),
    new(4, "Banana"),
};

WpfPlot1.Plot.Axes.Bottom.TickGenerator = new ScottPlot.TickGenerators.NumericManual(ticks);
WpfPlot1.Plot.Axes.Bottom.MajorTickStyle.Length = 0;
WpfPlot1.Plot.HideGrid();

// tell the plot to autoscale with no padding beneath the bars
WpfPlot1.Plot.Axes.Margins(bottom: 0);


WpfPlot1.Refresh();

条形填充样式

每个条形都可以单独设置样式。

// add bars with sample data
double[] values = { 3, 7, 9 };
var barPlot = WpfPlot1.Plot.Add.Bars(values);

// bars may be styled after they have been added
barPlot.Bars[0].FillColor = Colors.Orange;
barPlot.Bars[1].FillColor = Colors.Green;
barPlot.Bars[2].FillColor = Colors.Navy;

barPlot.Bars[0].FillHatch = new ScottPlot.Hatches.Striped();
barPlot.Bars[1].FillHatch = new ScottPlot.Hatches.Dots();
barPlot.Bars[2].FillHatch = new ScottPlot.Hatches.Checker();

foreach (var bar in barPlot.Bars)
{
    bar.LineWidth = 2;
    bar.LineColor = bar.FillColor.Darken(0.5);
    bar.FillHatchColor = bar.FillColor.Lighten(0.1);
}

// tell the plot to autoscale with no padding beneath the bars
WpfPlot1.Plot.Axes.Margins(bottom: 0);


WpfPlot1.Refresh();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

code_shenbing

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值