Jump to content

 

Photo

Using Datapoints in charts


  • Please log in to reply
27 replies to this topic

#1 Arun

Arun

    Advanced Member

  • Members
  • PipPipPip
  • 41 posts
  • Gender:Male

Posted 24 February 2012 - 07:54 AM

Hi guys,

          For my wpf application, i need to create month wise charts in which i have to use four datapoints for each month. four datapoints should be in bar type. how to create datapoints in simple form instead of creating 48 datapoints for all months. the datapoints value will be from web service which is used in that application. Please send some suggestion or links that would be needful.

thanks & regards,

Arun Kumar G

#2 sharmila

sharmila

    Advanced Member

  • Administrators
  • PipPipPip
  • 697 posts
  • Gender:Female

Posted 24 February 2012 - 12:59 PM

Hi Arun,

Are you trying to create a chart where each bar will have four DataPoints? If yes then you can create a StackedColumn chart as shown below.

<vc:Chart Width="500" Height="300" >
            <vc:Chart.Series>
                <vc:DataSeries LegendText="ProductA" RenderAs="StackedColumn" >
                    <vc:DataSeries.DataPoints>
                        <vc:DataPoint AxisXLabel="Jan" YValue="25"/>
                        <vc:DataPoint AxisXLabel="Feb" YValue="24"/>
                        <vc:DataPoint AxisXLabel="Mar" YValue="31"/>
                        <vc:DataPoint AxisXLabel="Apr" YValue="34"/>
                        <vc:DataPoint AxisXLabel="May" YValue="32"/>
                        <vc:DataPoint AxisXLabel="Jun" YValue="25"/>
                        <vc:DataPoint AxisXLabel="Jul" YValue="24"/>
                        <vc:DataPoint AxisXLabel="Aug" YValue="31"/>
                        <vc:DataPoint AxisXLabel="Sept" YValue="34"/>
                        <vc:DataPoint AxisXLabel="Oct" YValue="32"/>
                        <vc:DataPoint AxisXLabel="Nov" YValue="34"/>
                        <vc:DataPoint AxisXLabel="Dec" YValue="32"/>
                    </vc:DataSeries.DataPoints>
                </vc:DataSeries>
                <vc:DataSeries LegendText="ProductB" RenderAs="StackedColumn" >
                    <vc:DataSeries.DataPoints>
                        <vc:DataPoint YValue="33"/>
                        <vc:DataPoint YValue="22"/>
                        <vc:DataPoint YValue="30"/>
                        <vc:DataPoint YValue="38"/>
                        <vc:DataPoint YValue="31"/>
                        <vc:DataPoint YValue="82"/>
                        <vc:DataPoint YValue="64"/>
                        <vc:DataPoint YValue="95"/>
                        <vc:DataPoint YValue="86"/>
                        <vc:DataPoint YValue="61"/>
                        <vc:DataPoint YValue="38"/>
                        <vc:DataPoint YValue="61"/>
                    </vc:DataSeries.DataPoints>
                </vc:DataSeries>
                <vc:DataSeries LegendText="ProductC" RenderAs="StackedColumn" >
                    <vc:DataSeries.DataPoints>
                        <vc:DataPoint YValue="33"/>
                        <vc:DataPoint YValue="22"/>
                        <vc:DataPoint YValue="30"/>
                        <vc:DataPoint YValue="38"/>
                        <vc:DataPoint YValue="31"/>
                        <vc:DataPoint YValue="82"/>
                        <vc:DataPoint YValue="64"/>
                        <vc:DataPoint YValue="95"/>
                        <vc:DataPoint YValue="86"/>
                        <vc:DataPoint YValue="61"/>
                        <vc:DataPoint YValue="38"/>
                        <vc:DataPoint YValue="61"/>
                    </vc:DataSeries.DataPoints>
                </vc:DataSeries>
                <vc:DataSeries LegendText="ProductD" RenderAs="StackedColumn" >
                    <vc:DataSeries.DataPoints>
                        <vc:DataPoint YValue="33"/>
                        <vc:DataPoint YValue="22"/>
                        <vc:DataPoint YValue="30"/>
                        <vc:DataPoint YValue="38"/>
                        <vc:DataPoint YValue="31"/>
                        <vc:DataPoint YValue="82"/>
                        <vc:DataPoint YValue="64"/>
                        <vc:DataPoint YValue="95"/>
                        <vc:DataPoint YValue="61"/>
                        <vc:DataPoint YValue="86"/>
                        <vc:DataPoint YValue="61"/>
                        <vc:DataPoint YValue="38"/>
                    </vc:DataSeries.DataPoints>
                </vc:DataSeries>
            </vc:Chart.Series>
 </vc:Chart>
Please revert back if this does not fulfill your requirement. It will be helpful for us if you explain your requirement in detail.

Regards,
Sharmila

Attached Files



#3 Arun

Arun

    Advanced Member

  • Members
  • PipPipPip
  • 41 posts
  • Gender:Male

Posted 24 February 2012 - 01:44 PM

Thanks for your post sharmila,
As for my application i have used c# code to create datapoints. so to differ datapoints i have created 48 datapoints(may be i am wrong in this part) since i have to click a datapoint using mouse click event to display a datagrid with values . Please give any reference or suggestion regarding the same.

#4 sharmila

sharmila

    Advanced Member

  • Administrators
  • PipPipPip
  • 697 posts
  • Gender:Female

Posted 28 February 2012 - 02:03 PM

Hi Arun,

You can create StackedColumn chart in managed code as shown below.

public void CreateChart()
{
  chart.Width = 500;
  chart.Height = 300;

  for (int k = 0; k < 4; k++)
  {
   DataSeries ds = new DataSeries();
   ds.RenderAs = RenderAs.StackedColumn;
   for (int i = 0; i < 12; i++)
   {
    DataPoint dp = new DataPoint();
    dp.YValue = rn.Next(50, 100);
    ds.DataPoints.Add(dp);
   }
   chart.Series.Add(ds);
  }

   chart.Series[0].DataPoints[0].AxisXLabel ="Jan";
   chart.Series[0].DataPoints[1].AxisXLabel = "Feb";
   chart.Series[0].DataPoints[2].AxisXLabel = "Mar";
   chart.Series[0].DataPoints[3].AxisXLabel = "Apr";
   chart.Series[0].DataPoints[4].AxisXLabel = "May";
   chart.Series[0].DataPoints[5].AxisXLabel = "Jun";
   chart.Series[0].DataPoints[6].AxisXLabel = "Jul";
   chart.Series[0].DataPoints[7].AxisXLabel = "Aug";
   chart.Series[0].DataPoints[8].AxisXLabel = "Sep";
   chart.Series[0].DataPoints[9].AxisXLabel = "Oct";
   chart.Series[0].DataPoints[10].AxisXLabel = "Nov";
   chart.Series[0].DataPoints[11].AxisXLabel = "Dec";

   LayoutRoot.Children.Add(chart);
}

Please revert back if it does not solve your problem.

Regards,
Sharmila

#5 Arun

Arun

    Advanced Member

  • Members
  • PipPipPip
  • 41 posts
  • Gender:Male

Posted 28 February 2012 - 02:50 PM

Hi Sharmila,

As for my issue, example for Jan month i specify four datapoints and for each datapoint i used services to get the values. so for all months i have 48 values. How to use looping function here to vary 48 values since i am using mouse click event for all datapoints.Please help me on this.

#6 mac

mac

    Advanced Member

  • Members
  • PipPipPip
  • 171 posts
  • Gender:Male

Posted 29 February 2012 - 06:17 AM

Attach events with DataSeries only. Do not attach events with all DataPoints one by one. If you attach events with DataSeries it will be automatically attached with all DataPoints preset in that DataSeries.

#7 Arun

Arun

    Advanced Member

  • Members
  • PipPipPip
  • 41 posts
  • Gender:Male

Posted 02 March 2012 - 10:35 AM

Thanks for your post mac,sorry for the late reply guys,
mac, i tried giving mouse click event for data series and where can i give the list of items to display in data grid when i click the data point item. i found some difficulty to get the result. can u please post some sample code with mouse click event.

Thanks again,

Regards

Arun

#8 sharmila

sharmila

    Advanced Member

  • Administrators
  • PipPipPip
  • 697 posts
  • Gender:Female

Posted 05 March 2012 - 06:14 AM

Arun,

Can you please answer to my query below?
On click of DataSeries whether you want to display information of all DataPoints belonging to that DataSeries or you want to display information of DataPoint clicked?

Regards,
Sharmila

#9 Arun

Arun

    Advanced Member

  • Members
  • PipPipPip
  • 41 posts
  • Gender:Male

Posted 05 March 2012 - 12:49 PM

Arun,

Can you please answer to my query below?
On click of DataSeries whether you want to display information of all DataPoints belonging to that DataSeries or you want to display information of DataPoint clicked?

Regards,
Sharmila


Thanks for asking this query, i need to display information of datapoint since each datapoint represents list of records. so when i click a datapoint a list of records will be shown in datagrid.
Please reply if it is not clearing your query.

#10 vivek

vivek

    Advanced Member

  • Team Visifire
  • PipPipPip
  • 3,605 posts
  • Gender:Male
  • Location:Bangalore

Posted 06 March 2012 - 05:53 AM

Arun,

You can attach mouse event on DataSeries. Inside the event handler, you can access information related to each clicked DataPoint as shown below and display it inside the DataGrid.

void DataSeries_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            DataPoint dp = sender as DataPoint;
            String label = dp.AxisXLabel;
            Double yValue = dp.YValue;
        }

Regards,
Vivek
Team Visifire


#11 Arun

Arun

    Advanced Member

  • Members
  • PipPipPip
  • 41 posts
  • Gender:Male

Posted 06 March 2012 - 06:18 AM

Arun,

You can attach mouse event on DataSeries. Inside the event handler, you can access information related to each clicked DataPoint as shown below and display it inside the DataGrid.

void DataSeries_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            DataPoint dp = sender as DataPoint;
            String label = dp.AxisXLabel;
            Double yValue = dp.YValue;
        }


Thanks for the reply vivek. What will be the simpler way if i am using four charts with month wise data and i want to use mouse click event for each datapoint. Please refer this whole post and suggest me reg the same.

Regards,
Arun

#12 vivek

vivek

    Advanced Member

  • Team Visifire
  • PipPipPip
  • 3,605 posts
  • Gender:Male
  • Location:Bangalore

Posted 06 March 2012 - 06:23 AM

In that case you have to attach event on each series and get the data from the clicked DataPoint as shown above.

Regards,
Vivek
Team Visifire


#13 Arun

Arun

    Advanced Member

  • Members
  • PipPipPip
  • 41 posts
  • Gender:Male

Posted 06 March 2012 - 07:45 AM

In that case you have to attach event on each series and get the data from the clicked DataPoint as shown above.


As from your reply i have to mention each data point within that series, if i am having 12 datapoint within a series then i have to add 12 dp inside the data series event. Please help me if i am not clear.

#14 vivek

vivek

    Advanced Member

  • Team Visifire
  • PipPipPip
  • 3,605 posts
  • Gender:Male
  • Location:Bangalore

Posted 06 March 2012 - 12:48 PM

Whether you want to display information for a clicked DataPoint only or for all DataPoints in that series? Also, please tell me which chart type you are working with?

Regards,
Vivek
Team Visifire


#15 Arun

Arun

    Advanced Member

  • Members
  • PipPipPip
  • 41 posts
  • Gender:Male

Posted 06 March 2012 - 01:11 PM

Whether you want to display information for a clicked DataPoint only or for all DataPoints in that series? Also, please tell me which chart type you are working with?


Vivek,
I need to display information for a clicked data point only. Each data point represents some record count and i have to display the list of records using data grid when i click it. I have four charts includes 3 of type Line charts, one of type Stacked column.

#16 vivek

vivek

    Advanced Member

  • Team Visifire
  • PipPipPip
  • 3,605 posts
  • Gender:Male
  • Location:Bangalore

Posted 07 March 2012 - 04:27 AM

Then you can achieve it as I have shown above. Just attach event to DataSeries, and on click of a DataPoint you will get sender as DataPoint by which you can access information and display it inside the grid.

Regards,
Vivek
Team Visifire


#17 Arun

Arun

    Advanced Member

  • Members
  • PipPipPip
  • 41 posts
  • Gender:Male

Posted 12 March 2012 - 06:58 AM

Hi vivek,

Thanks for your kind reply. As per your suggestion, if i want to add list values to datapoints to display in grid how can we attach list values to datapoints. in your example we are getting datapoint yValue by code

Double yValue = dp.yValue;

But i have to show list values which will be get from service method inside the application. Here is the sample code which i used to display the list values in data grid in data point mouse click event.

void datapoint1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
SampleList={some service method to get list values}
datagrid1.Itemssource= SampleList;
datagrid1.Visibility=Visibility.Visible;
}
Here my difficulty is how can i attach distinct list values to each datapoints if i use mouse click event on data series. Need help on same.

Thanks again.

#18 vivek

vivek

    Advanced Member

  • Team Visifire
  • PipPipPip
  • 3,605 posts
  • Gender:Male
  • Location:Bangalore

Posted 12 March 2012 - 09:17 AM

Arun,

Can you please tell me the purpose of the list values in DataSeries? Where exactly you are using those list values?

Regards,
Vivek
Team Visifire


#19 Arun

Arun

    Advanced Member

  • Members
  • PipPipPip
  • 41 posts
  • Gender:Male

Posted 12 March 2012 - 09:26 AM

Arun,

Can you please tell me the purpose of the list values in DataSeries? Where exactly you are using those list values?


The data points in my charts represents the count of records. A record comprises of like empId, empName, empAge & empSalary. So when i click the data point, a data grid opens and shows the number of records with above said columns. I am getting the counts and record details bu creating service methods in my WPF-XBAP application. And my difficulty is i have to use four month wise charts and how to minimize the code part efficiently instead of creating 48 data points and using its mouse click events.
Thanks for asking this query.

#20 vivek

vivek

    Advanced Member

  • Team Visifire
  • PipPipPip
  • 3,605 posts
  • Gender:Male
  • Location:Bangalore

Posted 12 March 2012 - 11:42 AM

It seems you are trying to get the information from all DataPoints on a single click (over DataPoint). Am I correct? If yes, please note that inside the mouse event handler of DataSeries or DataPoint, you can get information from the clicked DataPoint only.

If you want to display information for all DataPoints on a single click, you can set a Tag property of DataSeries to SampleList.

Example:

dataSeries.Tag = SampleList;

Then inside the mouse event handler of DataSeries or DataPoint, get the SampleList from DataSeries's Tag as shown below:

void dataSeries_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
SampleList=(sender as DataPoint).Parent.Tag;
datagrid1.Itemssource= SampleList;
datagrid1.Visibility=Visibility.Visible;
}

Regards,
Vivek
Team Visifire





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users