0

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.

Tony L.
  • 17,638
  • 8
  • 69
  • 66
dx_over_dt
  • 13,240
  • 17
  • 54
  • 102

1 Answers1

0

To stack series, you need at least two: http://demos.telerik.com/aspnet-ajax/htmlchart/examples/functionality/stackedseries/defaultcs.aspx

One should have the YES votes for its values (i.e., the field provided in the DataFieldY property should have that number for each item on the x-axis). The other should provide the same for the NO votes.

Thus, you should have something like:

    <Series>
        <tel:BarSeries Stacked="true" DataFieldY="value_count_Yes">
            <Appearance FillStyle-BackgroundColor="Red" />
        </tel:BarSeries>
        <tel:BarSeries Stacked="true" DataFieldY="value_count_No">
            <Appearance FillStyle-BackgroundColor="Blue" />
        </tel:BarSeries>
    </Series>

I am not sure how your data is structured, so I am not sure how you can obtain this data. Perhaps you can generate a dynamic field in the SQL query itself that subtracts the yes votes from the total votes if that's what you have.

rdmptn
  • 5,413
  • 1
  • 16
  • 29