Sign in to follow this  
pickle

Multi-Series Column Single Y

Recommended Posts

My scenario:

 

I want a multi-series column chart to display data from a database. The y trend line is going to represent some average number throughout the chart. What I want to do is test to see if each column is above/below this average and change the color accordingly (i.e. if the column is below the average it would be red alerting the observer, otherwise it would be green). This seems doable, however I also want to show the two different column possibilities in the legend (red columns = 'Below Average', green columns = 'Above Average'). Essentially, because it is coming from a database and I don't know the values at compile-time, the chart could render columns in varying colors (i.e. red green red green...).

 

From what I have read, it seems the datasets and their values are going to match up with each label in the order they are written to the xml data. This is where I'm stuck, because some data may be written to one dataset while the next time around I need to write it to another (if I used two separate datasets). Is there a way to close a dataset and append data to it later? How do I solve this?

 

Thanks,

 

pickle

Share this post


Link to post
Share on other sites

Hi Pickle,

 

Welcome to FusionCharts Forum  :)

 

It seems that you are creating the XML dynamically after obtaining the values from the database. Since, the values come from the database at run time, you are finding it difficult to determine under which dataset (the one plotted in green or the one plotted in red) should the value fall into. To combat the situation, you may try the following steps and see if this helps.

 

1. Obtain all the values and calculate the average

2. Maintain two variables for each of the datasets

3. Run a loop to navigate through the contents of values list and compare each value with the average.

4. After comparing, you can add it either of the datasets applicable

5. After exiting the loop, close the datasets and append to the main variable of the chart.

 

By doing this, you will able to create the chart as per your requirement.

 

Hope this helps. :)

Share this post


Link to post
Share on other sites

Hi Haritha,

 

Sounds easy enough, but still one question. After I have compared all of the variables to the average and added them to the appropriate dataset container how will I add them into the graph's xml? It seems that the order in which you supply the data values is the order in which they are added to the labels, correct? If so, I don't know how I will be able to add some values of one dataset and some values of another throughout.

 

For example, I have 12 data labels, one for each month of the year. The first three months were above average, the second three were below, the next two were above, etc.. This goes back to a question in the original post that might make more sense now, is it possible to close off a dataset and add more data to it later?

 

Thanks,

 

pickle

Edited by pickle

Share this post


Link to post
Share on other sites

Maybe the easier solution, if possible, would be to customize the legend. That way I can just set the messages to the appropriate color in the legend. Would this be possible?

Share this post


Link to post
Share on other sites

Hi,

 

According to your requirement, we are modifying the code behind page of Multi-series chart present in the link : http://docs.fusioncharts.com/charts/contents/guide-for-web-developers/csnet/CS_DB.html

  String xmlData="";

// add chart element and categories obtained from database


  String xmlDataRed="", xmlDataGreen="";

  xmlDataRed+="<dataset seriesName='Below Average' color='DE1E25'>";
  xmlDataGreen+="<dataset seriesName='Above Average' color='4CBB47'>";

  string factoryquery3 = "select quantity from factory_output where factoryid="+factoryID;

    DbConn oRs2 = new DbConn(factoryquery3);
    int avg=0;
    while (oRs2.ReadData.Read())
    {
      // calculate average according to your need
	
    }
   while (oRs2.ReadData.Read())
    {
      if(avg<=oRs2.ReadData[0]) //red
	{
		xmlDataRed+="<set value='"+oRs2.ReadData[0]+"'/>";
	}
	else //green
	{
		xmlDataGreen+="<set value='"+oRs2.ReadData[0]+"'/>";
	}
	
    }
  
    oRs2.ReadData.Close();
    xmlDataRed+="</dataset>";
    xmlDataGreen+="</dataset>";

    xmlData+=xmlDataRed;
    xmlData+=xmlDataGreen;

    xmlData+="/chart";

Please implement the same by referring the code snippet above.

 

Hope this helps.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this