|
Line Chart 100% |
Posted by JC on Oct-22-2008 03:45 |
|
I have been trying to create a line chart 100%.
I have been prototyping using the same chart "Symbol Line Chart (2)"
So after setting the layer line width and before outputting the chart. I have this... which basically creates a stack line chart. What function do i need to use to create the 100%
Dim dblDummy(data0.Length - 1) As Double
Dim lineData As New ArrayMath(dblDummy)
layer.addDataSet(lineData.add(data0).result(), &HFF0000, "Quantum Computer").setDataSymbol(Chart.CircleSymbol, 9)
layer.addDataSet(lineData.add(data1).result(), &HFF00, "Atom Synthesizer").setDataSymbol(Chart.DiamondSymbol, 11)
layer.addDataSet(lineData.add(data2).result(), &HFF6600, "Proton Cannon").setDataSymbol(Chart.Cross2Shape(), 11) |
Re: Line Chart 100% |
Posted by Peter Kwan on Oct-22-2008 23:46 |
|
Hi JC,
I assume by "line chart 100%", you are referring to a chart like a "Percentage Area Chart", but use lines instead of areas.
The percentage values in your case should be 100 * (data0[n]) / (data0[n] + data1[n] + data2[n]). So I suggest the following code:
Dim scaleFactor() As Double = New ArrayMath(data0).add(data1).add(data2).div(100).result()
Dim accPercentageData0() As Double = New ArrayMath(data0).div(scaleFactor).result()
Dim accPercentageData1() As Double = New ArrayMath(data0).add(data1).div(scaleFactor).result()
'by definition, the last data series must be constant = 100
Dim accPercentageData2() As Double = New ArrayMath(data0).mul(0).add(100).result()
layer.addDataSet(accPercentageData0, &HFF0000, "Quantum Computer").setDataSymbol(Chart.CircleSymbol, 9)
layer.addDataSet(accPercentageData1, &HFF00, "Atom Synthesizer").setDataSymbol(Chart.DiamondSymbol, 11)
layer.addDataSet(accPercentageData2, &HFF6600, "Proton Cannon").setDataSymbol(Chart.Cross2Shape(), 11)
c.yAxis().setLinearScale(0, 100, 10)
c.yAxis().setLabelFormat("{value}%")
If you want to plot the percentage, but to also show the actual values in the tooltips, you may add:
layer.addExtraField2(data0)
layer.addExtraField2(data1)
layer.addExtraField2(data2)
In the tooltip configuration, you may then use {value} to represent the percentage, and {dsdiField0} to represent the original value.
Hope this can help.
Regards
Peter Kwan |
Re: Line Chart 100% |
Posted by JC on Dec-05-2008 02:49 |
|
I am wondering how can I deal with zero value data when creating "Stacked Line Chart"/"line chart 100%"
Using the code example you provided in previous thread.
When doing the calculation for the "scaleFactor", and item within the matharray object can be zero.
Items with "data0" can possibly be zero as well.
When assigning "accPercentageData0" item within the matharray object will be NaN.
Since the data is for reporting purpose, we can not remove zero data values. We also can not rearrange the columns to the specific order.
I have provided a screen shot on what the data can look like within a data table to help explain the issue. Illustrated in test1.GIF attachment
Currently the way the chart will render, the line to connect to and from the the zero data point will not display. Illustrated in test2.GIF attachment
|
Re: Line Chart 100% |
Posted by Peter Kwan on Dec-06-2008 00:34 |
|
Hi JC,
If the sum of the data is 0, the percertage is mathematically undefined. So leaving a gap seems a reasonable presentation method. Of course, you can use other presentation method.
In the followings, the code is modified slightly to draw lines that "jump over" the undefined positions:
Dim accPercentageData0() As Double = New ArrayMath(data0).financeDiv(scaleFactor, Chart.NoValue).result()
Dim accPercentageData1() As Double = New ArrayMath(data0).add(data1).financeDiv(scaleFactor, Chart.NoValue).result()
.......................
layer.setGapColor(Chart.SameAsMainColor);
Hope this can help.
Regards
Peter Kwan |
Re: Line Chart 100% |
Posted by JC on Dec-06-2008 05:45 |
|
With the data i provided in previous thread.
if i use that data and put it into 100% Bar/column (Chart.Percentage). The project name 'cindy project 03...' will display values of 33.33%. Is there be any way for me to do that base on your 100% line Chart example? |
Re: Line Chart 100% |
Posted by Peter Kwan on Dec-06-2008 13:21 |
|
Hi JC,
The original 100% Bar/column chart actually is a more mathematically accurate representation - the entire bar should remain as 100% even if all data points are 0. Consider the case that all data points are infinitely small (imagine 0.0000000000000000001). The total percentage is obviously 100%, no matter how small the data points are. It follows as all data points approach 0, the total percentage is 100%.
(In my original % line sample code, the top line should be 100%, even if all data points are 0. My original code hard coded it to 100.)
In a line chart, you can either skip the point (leave a gap) or "join through" the gap. In a bar chart, obviously you cannot "join through" the gap, as the bars do not join. So I assume you mean you want to leave a gap.
To leave a gap, please replace 0 with Chart.NoValue. For example:
For i = 0 To UBound(data0)
If data0(i) = 0 Then data0(i) = Chart.NoValue
If data1(i) = 0 Then data1(i) = Chart.NoValue
If data2(i) = 0 Then data2(i) = Chart.NoValue
Next
Hope this can help.
Regards
Peter Kwan |
|