views:

677

answers:

1

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.

+1  A: 

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.

Kezzer