Changing a Series Color in a Line Chart with Script
Hello,<br />
<br />
I'm having trouble changing the line color of a series in a line chart. <br />
<br />
I have successfully changed the colors of the markers (within beforeDrawDataPoint) and the legend (within beforeDrawLegendItem) but I'm having difficulties with the line color. The only way I've managed to change the line color is within beforeGeneration but, as a side effect, the outline of the markers are also changing from black to the color I'm assigning to the line.<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>function beforeDrawLegendItem( lerh, bounds, icsc )
{
var seriesValue = lerh.getLabel().getCaption().getValue();
var fill = lerh.getFill();
if( seriesValue == "141" )
fill.set( 250, 178, 23, 255 );
}
function beforeDrawDataPoint( dph, fill, icsc )
{
if( dph.getSeriesDisplayValue() == '141' )
fill.set( 250, 178, 23, 255 );
}
function beforeGeneration( chart, icsc )
{
importPackage( Packages.org.eclipse.birt.chart.model.attribute.impl );
var xAxis = chart.getAxes().get(0);
var yAxis = xAxis.getAssociatedAxes().get(0);
var xSeriesDef = xAxis.getSeriesDefinitions().get(0);
var ySeriesDef = yAxis.getSeriesDefinitions().get(0);
var ySeries = ySeriesDef.getRunTimeSeries();
var numberofrunseries = ySeries.size();
//loop thru all of the series
for (var i = 0; i < numberofrunseries; i++) {
//my condition
if ( ySeries.get(i).getSeriesIdentifier() == '141' ) {
ySeries.get(i).setPaletteLineColor(false);
ySeries.get(i).getLineAttributes().setColor( ColorDefinitionImpl.create( 250, 178, 23 ) );
i = numberofrunseries;
}
}
}</pre>
<br />
I spent some time researching this topic but haven't seen a solution that will help me out. <br />
<br />
<a class='bbc_url' href='http://www.birt-exchange.org/org/forum/index.php/topic/20136-change-chart-series-color-via-script-in-birt-2-3-1/page__s__4a21e3d43fa52b95e8e0e8ae9929310a'>Change chart series color via script in birt 2.3.1</a><br />
<a class='bbc_url' href='http://www.birt-exchange.org/org/forum/index.php/topic/22208-how-to-set-marker-color-different-from-line-color-in-chart/page__s__bcef1fddd7d83b95f5e5f3d48a6e38cd'>How to set marker color different from line color in chart?</a><br />
<a class='bbc_url' href='http://www.birt-exchange.org/org/forum/index.php/topic/14709-change-line-color-via-script-in-a-chart/page__s__52eca4c59bfd383d72646997320fb965'>Change line color via script in a chart </a><br />
<br />
I keep wandering back to the beforeDrawSeries but I can't seem to find anything in there that deal with the line attributes.<br />
<br />
I'm looking for help to either change the marker outline back to black OR just change the line of the series without affecting the marker outline. Any suggestions are appreciated. I've added an example report for reference.<br />
<br />
BIRT version 2.6.2<br />
<br />
Thanks in advance,<br />
Rich
<br />
I'm having trouble changing the line color of a series in a line chart. <br />
<br />
I have successfully changed the colors of the markers (within beforeDrawDataPoint) and the legend (within beforeDrawLegendItem) but I'm having difficulties with the line color. The only way I've managed to change the line color is within beforeGeneration but, as a side effect, the outline of the markers are also changing from black to the color I'm assigning to the line.<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>function beforeDrawLegendItem( lerh, bounds, icsc )
{
var seriesValue = lerh.getLabel().getCaption().getValue();
var fill = lerh.getFill();
if( seriesValue == "141" )
fill.set( 250, 178, 23, 255 );
}
function beforeDrawDataPoint( dph, fill, icsc )
{
if( dph.getSeriesDisplayValue() == '141' )
fill.set( 250, 178, 23, 255 );
}
function beforeGeneration( chart, icsc )
{
importPackage( Packages.org.eclipse.birt.chart.model.attribute.impl );
var xAxis = chart.getAxes().get(0);
var yAxis = xAxis.getAssociatedAxes().get(0);
var xSeriesDef = xAxis.getSeriesDefinitions().get(0);
var ySeriesDef = yAxis.getSeriesDefinitions().get(0);
var ySeries = ySeriesDef.getRunTimeSeries();
var numberofrunseries = ySeries.size();
//loop thru all of the series
for (var i = 0; i < numberofrunseries; i++) {
//my condition
if ( ySeries.get(i).getSeriesIdentifier() == '141' ) {
ySeries.get(i).setPaletteLineColor(false);
ySeries.get(i).getLineAttributes().setColor( ColorDefinitionImpl.create( 250, 178, 23 ) );
i = numberofrunseries;
}
}
}</pre>
<br />
I spent some time researching this topic but haven't seen a solution that will help me out. <br />
<br />
<a class='bbc_url' href='http://www.birt-exchange.org/org/forum/index.php/topic/20136-change-chart-series-color-via-script-in-birt-2-3-1/page__s__4a21e3d43fa52b95e8e0e8ae9929310a'>Change chart series color via script in birt 2.3.1</a><br />
<a class='bbc_url' href='http://www.birt-exchange.org/org/forum/index.php/topic/22208-how-to-set-marker-color-different-from-line-color-in-chart/page__s__bcef1fddd7d83b95f5e5f3d48a6e38cd'>How to set marker color different from line color in chart?</a><br />
<a class='bbc_url' href='http://www.birt-exchange.org/org/forum/index.php/topic/14709-change-line-color-via-script-in-a-chart/page__s__52eca4c59bfd383d72646997320fb965'>Change line color via script in a chart </a><br />
<br />
I keep wandering back to the beforeDrawSeries but I can't seem to find anything in there that deal with the line attributes.<br />
<br />
I'm looking for help to either change the marker outline back to black OR just change the line of the series without affecting the marker outline. Any suggestions are appreciated. I've added an example report for reference.<br />
<br />
BIRT version 2.6.2<br />
<br />
Thanks in advance,<br />
Rich
0
Comments
-
Thanks - I appreciate the reply.<br />
<br />
I actually want the outline. My problem seems to be that when I set the line color in the beforeGeneration it is changing the marker outline color as well. I tried adding the code below but it did not change the outline color.<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>function beforeDrawMarker( marker, dph, icsc )
{
importPackage( Packages.org.eclipse.birt.chart.model.attribute.impl );
marker.getOutline().setColor( ColorDefinitionImpl.create( 0, 0, 0 ) );
}</pre>
<br />
Also - I realized that in the example attached to the original post, I had the 'Use Series Palette as Line Color' unchecked by mistake for the Value (Y) Series. I meant to have that setting selected.<br />
<br />
Any other thoughts are appreciated.<br />
Rich0 -
You're wanting to assign a specific color to a specific series? Or could you just put your colors you're wanting into the palette and just let BIRT assign the colors? Even if I grab the marker in the beforeGeneration and try to change the outline color, it doesn't work. I've asked a couple colleagues as well. I'll let you know if we get anything.Warning No formatter is installed for the format ipb0
-
Well, I found a way to change just the outline color. The problem is, it doesn't work if you're not using the series palette color. It changes the entire line color if you don't use the series palette, so it doesn't help.Warning No formatter is installed for the format ipb0
-
<p>Hello BIRT community,</p><p> </p><p>I see that this solution is for the line chart. What if we have bar chart. Are the methods for setting the color the same like for the line chart?</p><p> </p><p>Thanks in advance.</p><p> </p><p>I found a solution. it is a combination of code posted here and on other topic:</p><p><a data-ipb='nomediaparse' href='http://www.birt-exchange.org/forum/index.php?/topic/22210-how-to-get-series-palette-from-bar-chart/'>http://www.birt-exchange.org/forum/index.php?/topic/22210-how-to-get-series-palette-from-bar-chart/</a></p><p> </p><p>This worked for me:</p><pre class="_prettyXprint _lang-js _linenums:1">sd = chart.getAxes().get(0).getAssociatedAxes().get(0).getSeriesDefinitions().get(0);sd.getSeriesPalette().getEntries().clear();sd.getSeriesPalette().getEntries().add(ColorDefinitionImpl.GREEN());// optional - orange with gradientsd.getSeriesPalette().getEntries().add(GradientImpl.create( ColorDefinitionImpl.create( 250, 178, 23 ), ColorDefinitionImpl.create( 250, 178, 23 ), -35, false ));</pre>Warning No formatter is installed for the format ipb0
Categories
- All Categories
- 107 Developer Announcements
- 53 Articles
- 104 General Questions
- 141 IM Services
- 43 OpenText Hackathon
- 32 Developer Tools
- 20.6K Analytics
- 4.1K AppWorks
- 8.9K Extended ECM
- 898 Cloud Fax and Notifications
- 76 Digital Asset Management
- 9.3K Documentum
- 29 eDOCS
- 118 Exstream
- 39.8K TeamSite
- 1.7K Web Experience Management