绘制柱形图,柱与柱之间没有空间
我正在使用 WPF 工具包,并尝试渲染一个看起来像直方图的图形。特别是,我希望每一列都与其他列相对应。列之间不应有间隙。
创建柱形图时需要应用许多组件。 (请参阅下面的示例 XAML)。有谁知道是否可以在其中一个元素上设置一个属性,该属性指的是列之间的空白宽度?
<charting:Chart Height="600" Width="Auto" HorizontalAlignment="Stretch" Name="MyChart"
Title="Column Graph" LegendTitle="Legend">
<charting:ColumnSeries
Name="theColumnSeries"
Title="Series A"
IndependentValueBinding="{Binding Path=Name}"
DependentValueBinding="{Binding Path=Population}"
Margin="0"
>
</charting:ColumnSeries>
<charting:Chart.Axes>
<charting:LinearAxis
Orientation="Y"
Minimum="200000"
Maximum="2500000"
ShowGridLines="True" />
<charting:CategoryAxis
Name="chartCategoryAxis"
/>
</charting:Chart.Axes>
</charting:Chart>
I am using the WPF toolkit, and am trying to render a graph that looks like a histogram. In particular, I want each column to be right up against each other column. There should be no gaps between columns.
There are a number of components that you apply when creating a column graph. (See example XAML below). Does anybody know if there is a property you can set on one of the elements which refers to the width of the white space between columns?
<charting:Chart Height="600" Width="Auto" HorizontalAlignment="Stretch" Name="MyChart"
Title="Column Graph" LegendTitle="Legend">
<charting:ColumnSeries
Name="theColumnSeries"
Title="Series A"
IndependentValueBinding="{Binding Path=Name}"
DependentValueBinding="{Binding Path=Population}"
Margin="0"
>
</charting:ColumnSeries>
<charting:Chart.Axes>
<charting:LinearAxis
Orientation="Y"
Minimum="200000"
Maximum="2500000"
ShowGridLines="True" />
<charting:CategoryAxis
Name="chartCategoryAxis"
/>
</charting:Chart.Axes>
</charting:Chart>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于没有神奇的答案,我从 codeplex 下载了 wpftoolkit 代码。
通过阅读代码,我可以看到在方法 ColumnSeries.UpdateDataPoint 中,有这样一行代码:
所以这是一个非常明确的“不”,您不能通过设置 public 来更改列之间的间隙财产。
我要尝试的解决方案是编写一个继承自ColumnSeries的新类,并重写UpdateDataPoint。
稍后编辑
好的,我开始工作了。如果有人感兴趣,我附上了 HistogramSeries 类的完整代码。
In the absence of magically-appearing answers, I downloaded the wpftoolkit code from codeplex.
By reading the code, I can see in the method ColumnSeries.UpdateDataPoint, there is this line of code:
So that's a pretty definitive "no", you cannot change the gap in between columns by setting a public property.
The solution which I'm going to try is to write a new class that inherits from ColumnSeries, and overriding UpdateDataPoint.
Later Edit
OK, I got it to work. In case anyone's interested, I've attached the full code for the HistogramSeries class.
感谢代码示例。这几乎正是我所需要的。我将其翻译成VB.Net并删除了小部分。
Thx for the code example. It was almost exactly what I have needed. I translated it into VB.Net and erased the minor parts.