图表控制多个ChartArea,同一个表

发布于 2024-08-04 23:17:23 字数 1660 浏览 5 评论 0原文

我有一个包含三列的表,后两列中有值。我正在尝试输出两个饼图,显示每个饼图的数据。由于某种原因,第二个饼图没有显示,而是显示为灰色方块。此外,图例连续出现两次,但这只是一个图例,对我来说毫无意义。

这是标记:

<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>

然后我有一个用于填充 DataSetSqlDataAdapter,然后将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一场信仰旅途 2024-08-11 23:17:23

好吧,我傻傻地花了一上午,但我解决了所有问题。图例的问题已解决,因为您需要像这样针对系列指定图例:

      <asp:Chart Height="500" Width="500" ID="ClientModelChart" runat="server">
        <Legends>
          <asp:Legend Name="PortfolioActual"></asp:Legend>
          <asp:Legend Enabled="false" Name="ModelActual"></asp:Legend>
        </Legends>
        <Series>
          <asp:Series ChartType="Pie" Legend="PortfolioActual" ChartArea="PortfolioActual" IsValueShownAsLabel="true" Name="PortfolioActual"></asp:Series>
          <asp:Series ChartType="Pie" Legend="ModelActual" ChartArea="ModelActual" IsValueShownAsLabel="true" Name="ModelActual"></asp:Series>
        </Series>
        <ChartAreas>
          <asp:ChartArea Area3DStyle-Enable3D="true" Area3DStyle-LightStyle="Realistic" Name="PortfolioActual"></asp:ChartArea>
          <asp:ChartArea Area3DStyle-Enable3D="true" Area3DStyle-LightStyle="Realistic" Name="ModelActual"></asp:ChartArea>
        </ChartAreas>
      </asp:Chart>

并且绑定数据应该像这样完成:

Dim sectorList As IList = CType(ds.Tables(1), IListSource).GetList()

ClientModelChart.Series("PortfolioActual").Points.DataBindXY(sectorList, "Sector", sectorList, "Model")
ClientModelChart.Series("ModelActual").Points.DataBindXY(sectorList, "Sector", sectorList, "Client")
ClientModelChart.Series("PortfolioActual")("PieLabelStyle") = "Outside"
ClientModelChart.Series("ModelActual")("PieLabelStyle") = "Outside"

最终到达那里。

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:

      <asp:Chart Height="500" Width="500" ID="ClientModelChart" runat="server">
        <Legends>
          <asp:Legend Name="PortfolioActual"></asp:Legend>
          <asp:Legend Enabled="false" Name="ModelActual"></asp:Legend>
        </Legends>
        <Series>
          <asp:Series ChartType="Pie" Legend="PortfolioActual" ChartArea="PortfolioActual" IsValueShownAsLabel="true" Name="PortfolioActual"></asp:Series>
          <asp:Series ChartType="Pie" Legend="ModelActual" ChartArea="ModelActual" IsValueShownAsLabel="true" Name="ModelActual"></asp:Series>
        </Series>
        <ChartAreas>
          <asp:ChartArea Area3DStyle-Enable3D="true" Area3DStyle-LightStyle="Realistic" Name="PortfolioActual"></asp:ChartArea>
          <asp:ChartArea Area3DStyle-Enable3D="true" Area3DStyle-LightStyle="Realistic" Name="ModelActual"></asp:ChartArea>
        </ChartAreas>
      </asp:Chart>

and binding the data should be done like this instead:

Dim sectorList As IList = CType(ds.Tables(1), IListSource).GetList()

ClientModelChart.Series("PortfolioActual").Points.DataBindXY(sectorList, "Sector", sectorList, "Model")
ClientModelChart.Series("ModelActual").Points.DataBindXY(sectorList, "Sector", sectorList, "Client")
ClientModelChart.Series("PortfolioActual")("PieLabelStyle") = "Outside"
ClientModelChart.Series("ModelActual")("PieLabelStyle") = "Outside"

Got there in the end.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文