Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Line Chart Using Chart Engine API
cgswtsu78
Hello,
How do I change the actual color of the line in a line chart using the chart engine api? I would have thought the below code would have done it, but that just changes the markers on the line color and not the acutal lines color.
LineSeries ls1 = (LineSeries) LineSeriesImpl.create( );
ls1.getLineAttributes( ).setColor( ColorDefinitionImpl.BLUE());
Also, is there any way to show the marker value (the actual Y axis value) in some cases but not others? It looks like it's an always show or never show using the below. I have a bunch of 0 Y axis values and I don't want the 0 to show. I only want to show the value when it's not 0
ls1.getLabel( ).setVisible( false );
Find more posts tagged with
Comments
JasonW
Take a look at this example:
I use the setscript to make the labels conditional. Just change the condition.
I use the getPalette and getLineAttributes to set the colors.
public static final Chart createOverlayLine( )
{
ChartWithAxes cwaLine = ChartWithAxesImpl.create( );
cwaLine.setType( "Line Chart" ); //$NON-NLS-1$
//Script
cwaLine.setScript( "function beforeDrawDataPointLabel( dph, label, icsc )" +
"{"+
"if( dph.getOrthogonalValue() < 20 ){"+
"label.setVisible(false);"+
"}"+
"}");
// Plot
cwaLine.getBlock( ).setBackground( ColorDefinitionImpl.WHITE( ) );
Plot p = cwaLine.getPlot( );
p.getClientArea( ).setBackground( ColorDefinitionImpl.create( 255,
255,
225 ) );
// Legend
cwaLine.getLegend( ).setVisible( true );
// X-Axis
Axis xAxisPrimary = cwaLine.getPrimaryBaseAxes( )[0];
xAxisPrimary.setType( AxisType.LINEAR_LITERAL );
DataElement max = NumberDataElementImpl.create(100);
DataElement min = NumberDataElementImpl.create(0);
xAxisPrimary.getScale().setMax(max);
xAxisPrimary.getScale().setMin(min);
xAxisPrimary.getScale().setStep(10);
// Y-Axis
Axis yAxisPrimary = cwaLine.getPrimaryOrthogonalAxis( xAxisPrimary );
//yAxisPrimary.setLabelSpan(100);
// Data Set
NumberDataSet categoryValues = NumberDataSetImpl.create( new double[]{
10, 25, 85} );//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
NumberDataSet orthoValues1 = NumberDataSetImpl.create( new double[]{
25, 35, 15
} );
NumberDataSet orthoValues2 = NumberDataSetImpl.create( new double[]{
10, 10, 25
} );
// X-Series
Series seCategory = SeriesImpl.create( );
seCategory.setDataSet( categoryValues );
SeriesDefinition sdX = SeriesDefinitionImpl.create( );
xAxisPrimary.getSeriesDefinitions( ).add( sdX );
sdX.getSeries( ).add( seCategory );
// Y-Sereis
LineSeries ls1 = (LineSeries) LineSeriesImpl.create( );
ls1.setDataSet( orthoValues1 );
ls1.getLineAttributes( ).setColor( ColorDefinitionImpl.BLUE( ) );
ls1.getLabel( ).setVisible( true );
Trigger tr1 = TriggerImpl.create(TriggerCondition.ONMOUSEOVER_LITERAL, ActionImpl.create(ActionType.SHOW_TOOLTIP_LITERAL, TooltipValueImpl.create(200, null)));
ls1.getTriggers().add(tr1);
SeriesDefinition sdY = SeriesDefinitionImpl.create( );
sdY.getSeriesPalette( ).update( ColorDefinitionImpl.BLUE( ) );
//sdY.getSeriesPalette( ).shift( -2 );
yAxisPrimary.getSeriesDefinitions( ).add( sdY );
sdY.getSeries( ).add( ls1 );
return cwaLine;
}
Jason
cgswtsu78
ok, thanks for the great example Jason that worked perfectly.
One more issue I'm facing with my 3d line chart is using a fixed width and having all of text that describe the datapoints fitting within that fixed width. Does the chart engine api have the capability to do an auto fit to the elements in the chart and basically dynamically draw/size the image accordingly? If that isn't possible I guess the next best option is to use static labels for the data points (point1, point 2...etc) and then have a mouse rollover on them and shoe the actual...is that possible?
Thanks for your suggestions.
-Colin