C#ScottPlot绘制堆积条形图

绘制堆积在一起的条形图

using ScottPlot; //ScottPlot命名空间别忘记
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

//下面只写绘制stacked bar Graph代码
public void Stacked_Bar()
{
	//formsPlot1是你拖拽带设计界面上的控件name
	var plt = formsPlot1.Plot;
	
	double[] valuesA = { 1, 2, 3, 2, 1, 2, 1 };
    double[] valuesB = { 3, 3, 2, 1, 3, 2, 1 };

	double[] valuesB2 = new double[valuesB.Length];
	for(int i=0; i<valuesB.Length; i++)
	{
		valuesB2[i] = valuesA[i] + valuesB[i];
	}
	//一定要先绘制相加后的结果valuesB2
	plt.AddBar(valuesB2);
    plt.AddBar(valuesA);
    //adjust axis limits so there is no padding below the bar graph
    //若是不设置yMin=0,你会发现图像不是从y轴等于0处一下整体显示出来,图像下方还有部分内容
	plt.SetAxisLimits(yMin: 0);
	
	formsPlot1.Refresh();
}

图片里还显示了数字,是因为我在我的代码里设置了。
C#ScottPlot绘制堆积条形图_第1张图片

你可能感兴趣的:(ScottPlot,c#,开发语言)