I'm making a pretty simple polling app. Users text a certain number with the values 'yes' or 'no' and the results show up live via AJAX on a projector. There are five different items to vote on (all yes or no).
Right now I have a SQL View that returns [poll_name, vote_value, value_count]
where vote_value is either 'yes' or 'no'.
Using RadHtmlChart, I'm trying to display a stacked BarChart with a bar for each poll_name
, a red bar for no votes and a blue bar for yes votes. I tried to alter the code from the BarChart example and merge it with the SqlDataSource example:
<asp:SqlDataSource ID="sqlResults" runat="server" ConnectionString="<%$ ConnectionStrings:MyDB %>"
SelectCommand="select poll_name, vote_value, value_count from vw_sms_pollResults order by poll_id" />
<tel:RadScriptManager runat="server" ID="rsmScriptManager" />
<tel:RadAjaxPanel runat="server" ID="rapPanel" LoadingPanelID="ralpLoadingPanel" EnableAJAX="true">
<tel:RadHtmlChart runat="server" ID="rhcResults" Width="800" Height="500" Transitions="true" DataSourceID="sqlResults">
...
<PlotArea>
<Appearance>
<FillStyle BackgroundColor="White" />
</Appearance>
<XAxis DataLabelsField="poll_name">
<MajorGridLines Visible="false" />
<MinorGridLines Visible="false" />
</XAxis>
<YAxis AxisCrossingValue="0">
<MajorGridLines Visible="false" />
<MinorGridLines Visible="false" />
</YAxis>
<Series>
<tel:BarSeries Stacked="true" DataFieldY="value_count">
<Appearance FillStyle-BackgroundColor="Red" />
</tel:BarSeries>
</Series>
</PlotArea>
</tel:RadHtmlChart>
</tel:RadAjaxPanel>
Unfortunately, I end up with twice as many bars as I want: a 'yes' and a 'no' for each poll_name
, they're all the same color (obviously), and they're not stacked. Ideally I would be able to tell it create a new BarSeries
for each value of (ie, group by) vote_value
.
How should I go about either massaging the data or changing my markup to fix this? In the future I'd like to allow an arbitrary number of responses, so I'm loathe to changing my query to simply have a 'yes_count' and 'no_count' columns, but I may have to in the meantime.