Novacode 折线图类型
Novacode LineChart type
我有一个实现 Novacode.LineChart
的代码。默认显示的折线图类型是这个:
但是我不想要这种类型的图表,我想要没有点数的,像这样:
这是我创建图表的代码:
LineChart c = new LineChart();
c.AddLegend(ChartLegendPosition.Bottom, false);
c.Grouping = Grouping.Stacked;
有谁知道我怎样才能隐藏那些点而只显示线?谢谢大家!!
我在搜索完全相同的功能时出现了您的问题。它可能有点,但我希望它对其他需要此功能的人有用。
我所谓的答案只不过是几行肮脏且难以管理的黑客,所以除非您不是迫切需要,否则我不建议您遵循这种方式。
我也不知道这是否是一种批准的方法,但我更喜欢逐步编写解决方案,这样可以帮助您掌握概念并使用更好的方法。
在我意识到我无法使用 DocX 创建没有标记的折线图后,使用当前提供的 API,我想知道实际输出和期望输出之间有什么区别。因此,在手动将图表编辑为预期结果后,我保存了一份带有折线图的 .docx 文件副本。
Before and after the edit
您可能已经知道,.docx 是一种容器格式,基本上由几个不同的文件夹和文件组成。您可以使用 .zip 存档提取器打开它。我为此任务使用了 7-Zip,并在 /word/charts/chart1.xml 的位置找到了图表文件,但这可能因文件而异,但您可以轻松计算出来了。
比较了两个 chart1.xml 文件,不同之处在于,没有标记的文件有额外的 XML 标签和附加属性;
<c:marker>
<c:symbol val="none" />
</c:marker>
我不得不以某种方式将这段代码添加到图表中。我将这些添加到 DocX 提供的示例代码中。您可以通过以下方式跟进:DocX/ChartSample.cs at master
这就是乐趣的开始。先简单的部分。
using System.Xml;
using System.Xml.Linq;
using Xceed.Words.NET;
// Create a line chart.
var line_chart = new LineChart();
// Create the data.
var PlaceholderData = ChartData.GenerateRandomDataForLinechart();
// Create and add series
var Series_1 = new Series("Your random chart with placeholder data");
Series_1.Bind(PlaceholderData, "X-Axis", "Y-Axis");
line_chart.AddSeries(Series_1);
// Create a new XmlDocument object and clone the actual chart XML
XmlDocument XMLWithNewTags = new XmlDocument();
XMLWithNewTags.LoadXml(line_chart.Xml.ToString());
我用过 XPath Visualizer Tool to determine the XPath query,了解这一点很重要,因为您不能只将标记标签添加到某个地方并期望它起作用。我为什么要讲这个?因为我在随机行上附加了标记标签并希望它能工作。天真.
// Set a namespace manager with the proper XPath location and alias
XmlNamespaceManager NSMngr = new XmlNamespaceManager(XMLWithNewTags.NameTable);
string XPathQuery = "/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser";
string xmlns = "http://schemas.openxmlformats.org/drawingml/2006/chart";
NSMngr.AddNamespace("c", xmlns);
XmlNode NewNode = XMLWithNewTags.SelectSingleNode(XPathQuery, NSMngr);
现在在新创建的 XML 具有指定命名空间的文档对象上创建必要的标签
XmlElement Symbol = XMLWithNewTags.CreateElement("c", "symbol", xmlns);
Symbol.SetAttribute("val", "none");
XmlElement Marker = XMLWithNewTags.CreateElement("c", "marker", xmlns);
Marker.AppendChild(Symbol);
NewNode.AppendChild(Marker);
并且我们应该将最新更改的内容复制到actual XML对象中。但是哎呀,可以理解它被定义为私有的,所以它是一个只读对象。这是我想 "Okay, I've fiddled enough with this. I better find another library" 但后来因为某些原因决定继续的地方。
已下载 DocX 存储库,将 this 行更改为
get; set;
重新编译,复制Xceed.Words.NET.dll到projectfolder/packages和projectfolder/projectname/bin/Debug文件夹,最后几行是
// Copy the contents of latest changes to actual XML object
line_chart.Xml = XDocument.Parse(XMLWithNewTags.InnerXml);
// Insert chart into document
document.InsertChart(line_chart);
// Save this document to disk.
document.Save();
值得吗?我不确定,但我在研究它的过程中学到了一些东西。这个答案中可能有很多糟糕的编程实践,所以 请 如果您看到一个请告诉我。对不起我的英语。
我有一个实现 Novacode.LineChart
的代码。默认显示的折线图类型是这个:
但是我不想要这种类型的图表,我想要没有点数的,像这样:
这是我创建图表的代码:
LineChart c = new LineChart();
c.AddLegend(ChartLegendPosition.Bottom, false);
c.Grouping = Grouping.Stacked;
有谁知道我怎样才能隐藏那些点而只显示线?谢谢大家!!
我在搜索完全相同的功能时出现了您的问题。它可能有点,但我希望它对其他需要此功能的人有用。
我所谓的答案只不过是几行肮脏且难以管理的黑客,所以除非您不是迫切需要,否则我不建议您遵循这种方式。
我也不知道这是否是一种批准的方法,但我更喜欢逐步编写解决方案,这样可以帮助您掌握概念并使用更好的方法。
在我意识到我无法使用 DocX 创建没有标记的折线图后,使用当前提供的 API,我想知道实际输出和期望输出之间有什么区别。因此,在手动将图表编辑为预期结果后,我保存了一份带有折线图的 .docx 文件副本。
Before and after the edit
您可能已经知道,.docx 是一种容器格式,基本上由几个不同的文件夹和文件组成。您可以使用 .zip 存档提取器打开它。我为此任务使用了 7-Zip,并在 /word/charts/chart1.xml 的位置找到了图表文件,但这可能因文件而异,但您可以轻松计算出来了。
比较了两个 chart1.xml 文件,不同之处在于,没有标记的文件有额外的 XML 标签和附加属性;
<c:marker>
<c:symbol val="none" />
</c:marker>
我不得不以某种方式将这段代码添加到图表中。我将这些添加到 DocX 提供的示例代码中。您可以通过以下方式跟进:DocX/ChartSample.cs at master
这就是乐趣的开始。先简单的部分。
using System.Xml;
using System.Xml.Linq;
using Xceed.Words.NET;
// Create a line chart.
var line_chart = new LineChart();
// Create the data.
var PlaceholderData = ChartData.GenerateRandomDataForLinechart();
// Create and add series
var Series_1 = new Series("Your random chart with placeholder data");
Series_1.Bind(PlaceholderData, "X-Axis", "Y-Axis");
line_chart.AddSeries(Series_1);
// Create a new XmlDocument object and clone the actual chart XML
XmlDocument XMLWithNewTags = new XmlDocument();
XMLWithNewTags.LoadXml(line_chart.Xml.ToString());
我用过 XPath Visualizer Tool to determine the XPath query,了解这一点很重要,因为您不能只将标记标签添加到某个地方并期望它起作用。我为什么要讲这个?因为我在随机行上附加了标记标签并希望它能工作。天真.
// Set a namespace manager with the proper XPath location and alias
XmlNamespaceManager NSMngr = new XmlNamespaceManager(XMLWithNewTags.NameTable);
string XPathQuery = "/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser";
string xmlns = "http://schemas.openxmlformats.org/drawingml/2006/chart";
NSMngr.AddNamespace("c", xmlns);
XmlNode NewNode = XMLWithNewTags.SelectSingleNode(XPathQuery, NSMngr);
现在在新创建的 XML 具有指定命名空间的文档对象上创建必要的标签
XmlElement Symbol = XMLWithNewTags.CreateElement("c", "symbol", xmlns);
Symbol.SetAttribute("val", "none");
XmlElement Marker = XMLWithNewTags.CreateElement("c", "marker", xmlns);
Marker.AppendChild(Symbol);
NewNode.AppendChild(Marker);
并且我们应该将最新更改的内容复制到actual XML对象中。但是哎呀,可以理解它被定义为私有的,所以它是一个只读对象。这是我想 "Okay, I've fiddled enough with this. I better find another library" 但后来因为某些原因决定继续的地方。
已下载 DocX 存储库,将 this 行更改为
get; set;
重新编译,复制Xceed.Words.NET.dll到projectfolder/packages和projectfolder/projectname/bin/Debug文件夹,最后几行是
// Copy the contents of latest changes to actual XML object
line_chart.Xml = XDocument.Parse(XMLWithNewTags.InnerXml);
// Insert chart into document
document.InsertChart(line_chart);
// Save this document to disk.
document.Save();
值得吗?我不确定,但我在研究它的过程中学到了一些东西。这个答案中可能有很多糟糕的编程实践,所以 请 如果您看到一个请告诉我。对不起我的英语。