图表控制多个ChartArea,同一个表
我有一个包含三列的表,后两列中有值。我正在尝试输出两个饼图,显示每个饼图的数据。由于某种原因,第二个饼图没有显示,而是显示为灰色方块。此外,图例连续出现两次,但这只是一个图例,对我来说毫无意义。
这是标记:
<asp:Chart Height="500" Width="500" ID="ClientModelChart" runat="server">
<Series>
<asp:Series ChartType="Pie" IsValueShownAsLabel="true" Name="PortfolioActual"></asp:Series>
<asp:Series ChartType="Pie" IsValueShownAsLabel="true" Name="ModelActual"></asp:Series>
</Series>
<Legends>
<asp:Legend Name="PortfolioActual"></asp:Legend>
<asp:Legend Name="ModelActual"></asp:Legend>
</Legends>
<ChartAreas>
<asp:ChartArea Area3DStyle-Enable3D="true" Area3DStyle-LightStyle="Realistic" Name="PortfolioActual"></asp:ChartArea>
<asp:ChartArea Area3DStyle-Enable3D="true" Name="ModelActual"></asp:ChartArea>
</ChartAreas>
</asp:Chart>
然后我有一个用于填充 DataSet
的 SqlDataAdapter
,然后将 DataTableCollection
转换为 IEnumerable< /code> 列表类型,以便我可以在数据绑定图表系列时使用它。这看起来有点毛茸茸的,但我这样做的原因是因为
DataSet
用于稍后的一些 XSLT 输出,所以当我已经获得了数据时,没有必要重新查询数据库。需要/想要。
Dim sectorList As IList = CType(ds.Tables(1), IListSource).GetList()
ClientModelChart.Series("PortfolioActual").Points.DataBind(sectorList, "Sector", "Model", Nothing)
ClientModelChart.Series("ModelActual").Points.DataBind(sectorList, "Sector", "Client", Nothing)
因此,第二个饼图(ModelActual)根本不显示,它只是一个灰色方块。我已经摆弄了几个小时但毫无结果。 (编辑:另外,我已经做了类似的事情,所以我不知道为什么这个不起作用。与我的另一个的区别在于它最初来自两组不同的数据,但这不应该是它不起作用的原因)
谢谢。
I've got a table with three columns, the latter two with values in them. I'm trying to output two pie charts displaying the data for each one. For some reason, the second pie chart isn't displaying, instead it's coming up as a gray square. Additionally the legend is appearing twice consecutively, but it's only a single legend which makes no sense to me.
Here's the markup:
<asp:Chart Height="500" Width="500" ID="ClientModelChart" runat="server">
<Series>
<asp:Series ChartType="Pie" IsValueShownAsLabel="true" Name="PortfolioActual"></asp:Series>
<asp:Series ChartType="Pie" IsValueShownAsLabel="true" Name="ModelActual"></asp:Series>
</Series>
<Legends>
<asp:Legend Name="PortfolioActual"></asp:Legend>
<asp:Legend Name="ModelActual"></asp:Legend>
</Legends>
<ChartAreas>
<asp:ChartArea Area3DStyle-Enable3D="true" Area3DStyle-LightStyle="Realistic" Name="PortfolioActual"></asp:ChartArea>
<asp:ChartArea Area3DStyle-Enable3D="true" Name="ModelActual"></asp:ChartArea>
</ChartAreas>
</asp:Chart>
Then I've got a SqlDataAdapter
used to fill a DataSet
, I then turn the DataTableCollection
into an IEnumerable
list type so I can use it when data binding the chart series. It seems a bit hairy, but the reason I do this is because the DataSet
is used for some XSLT output later on, so there's no point re-querying the database when I've already got the data I need/want.
Dim sectorList As IList = CType(ds.Tables(1), IListSource).GetList()
ClientModelChart.Series("PortfolioActual").Points.DataBind(sectorList, "Sector", "Model", Nothing)
ClientModelChart.Series("ModelActual").Points.DataBind(sectorList, "Sector", "Client", Nothing)
So the second pie chart (ModelActual) isn't displaying at all, it's just a gray square. I've been fiddling for hours with no avail. (EDIT: Also, I've already done something similar so I don't know why this one isn't working. The difference with my other one is that it came from two separate sets of data initially, but that shouldn't be the reason it doesn't work)
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我傻傻地花了一上午,但我解决了所有问题。图例的问题已解决,因为您需要像这样针对系列指定图例:
并且绑定数据应该像这样完成:
最终到达那里。
Okay, I spent the morning on it stupidly, but I solved all the problems. The issue with the legend was solved because you need to specify the legend against the series like so:
and binding the data should be done like this instead:
Got there in the end.