ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  re: Bar chart inquiry
Posted by Mike on Jul-04-2012 11:52
Hello,

   I am using chart director for my school project, and I find it very useful.

However, i have a question which i would like to seek your help.

Supposely, I would like to use the bar chart to display a weekly store performance from monday to saturday, and I  want the chart to be colred in red on a particular day if the number of sold items on that day is less than or equal to X. Otherwise, the chart on that day is green.

Since i am new to chart director, I'd like to ask you if you could give me some advice on how could i approach it.

Thanks for all of your help,

Mike

  re: Bar chart inquiry
Posted by Peter Kwan on Jul-05-2012 00:14
Hi Mike,

You can separate your data series into two data series, one for the red data, and one for the green data. For example, in Java:

//separate into two data series
double[] redData = new double[myData.length];
double[] greenData = new double[myData.length];

for (int i = 0; i < myData.length; ++i) {
    if (myData[i] <= X) redData[i] = myData[i];
    else greenData[i] = myData[i];
}

//draw the two series as red and green
BarLayer layer = c.addBarLayer2(Chart.Side);
layer.addDataSet(redData, 0xff0000);
layer.addDataSet(greenData, 0x00ff00);

Hope this can help.

Regards
Peter Kwan

  re: Bar chart inquiry
Posted by Mike on Jul-13-2012 20:42
Hello Peter,

  Thank for your help. I applied and it worked great.

May I ask you a more question relating to the display of many data points labels  in X axis?  Since I have about 30  data points labels namely date in MM/DD/YYYY format that I'd like to display in the x axis, and the same 30 data points namely sale voume in the Y axis . I'd like to ask  how could i display the MM/DD/YYYY data labels nicely in X axis? I tried many ways but  the  MM/DD/YYYY labels were distorted , and they did not appear rightly. Please help me if you could.

Thanks again and have a great day,

Mike

  re: Bar chart inquiry
Posted by Peter Kwan on Jul-14-2012 00:53
Hi Mike,

There are many ways to display labels.

If you want to display all 30 labels, and your chart is not wide enough, you may rotate the labels by 90 degrees. You may refer to "Trend Line Chart" sample code for an example the (the third chart in "http://www.advsofteng.com/gallery_trend.html"). The code is like:

c.xAxis().setLabels(myArrayOfTextStrings);

//arial 8 pts black rotate by 90 degrees
c.xAxis().setLabelStyle("Arial", 8, 0x000000, 90);

Note that the above assume your labels are an array of text strings (which means you have already formatted the dates to "MM/DD/YYYY"). If your labels are java.util.Date[], you may instead use the following code to ask ChartDirector to format them for you.

c.xAxis().setLabels2(myArrayOfTextStrings, "{value|mm/dd/yyyy}");

If your labels are predictable, it may be possible to skip some labels. (For example, if the dates are consecutive, they are predictable, and you can skip some labels and the chart is still understandable. If the dates are the dates that earthquake occurs, they are unpredictable and you may need to include all the labels without skipping.) If you would like to skip some labels, you may use Axis.setLabelStep. For example:

//display 1 out of 5 labels
c.xAxis().setLabelStep(5);

There are other strategies, such as removing the "YYYY" part to make the label shorter. This is acceptable if the labels are consecutive dates (which means that are all from the same year or are from the end of one year to the beginning of next year). You can put the full date range in the axis title. In this case, it would be obvious to the user what is the year, and you can keep the labels short and avoid repeating the same year in the labels over and over again.

Hope this can help.

Regards
Peter Kwan