2

我在 C# 应用程序中使用 MigraDoc 创建了以下图表:

Chart chart = new Chart(ChartType.Bar2D);
chart.Width = "10cm";
chart.Height = "10cm";
Series series = chart.SeriesCollection.AddSeries();
series.Add(new double[] { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 });
XSeries xseries = chart.XValues.AddXSeries();
xseries.Add("A", "B", "C", "D", "E", "F", "G", "H", "I", "J");
chart.XAxis.MajorTickMark = TickMarkType.Outside;
chart.XAxis.Title.Caption = "X-Axis";
chart.YAxis.MajorTickMark = TickMarkType.Outside;
chart.YAxis.HasMajorGridlines = true;
chart.PlotArea.LineFormat.Color = Colors.AliceBlue;
chart.PlotArea.LineFormat.Width = 1;
chart.PlotArea.LineFormat.Visible = true;
MigraDocObject.Add(chart);

现在假设我想成为 bar A inColors.AliceBlue和 bar B in Colors.DarkGray。我怎样才能做到这一点?是否可以通过官方API?还是我必须破解 MigraDoc?

4

2 回答 2

5

my solution:

Series series = chart.SeriesCollection.AddSeries();
series.Add(new double[] { 3, 10, 10, 150, 7, 192, 6 });
var elements = series.Elements.Cast<MigraDoc.DocumentObjectModel.Shapes.Charts.Point>().ToArray();
elements[0].FillFormat.Color = Colors.Chartreuse;
elements[3].FillFormat.Color = Colors.DeepSkyBlue;
于 2014-06-11T21:18:10.673 回答
0

我能想到的唯一方法是为每个要以不同颜色着色的条具有不同的系列。您将不得不对您的价值观进行一些修改,并且几乎覆盖了您的所有条形。

Series seriesA = chart.SeriesCollection.AddSeries();
seriesA.Add(new double[] { 10, 0, 0, 0, 0, 0, 0, 0, 0, 0 });
seriesA.FillFormat.Color = Colors.AliceBlue;

Series seriesB = chart.SeriesCollection.AddSeries();
seriesB.Add(new double[] { 0, 20, 0, 0, 0, 0, 0, 0, 0, 0 });
seriesB.FillFormat.Color = Colors.DarkGray;

Series seriesC = chart.SeriesCollection.AddSeries();
seriesC.Add(new double[] { 0, 0, 30, 0, 0, 0, 0, 0, 0, 0 });
seriesC.FillFormat.Color = Colors.Red;

只需确保每个新系列都引用您的相同图表对象。如果您能提供帮助,请确保将您的 series.HasDataLabel = false 设为您的系列值不会相互重叠。

根据图表的大小和复杂性,这应该很容易复制/粘贴。

于 2013-10-03T21:35:28.750 回答