Jump to content
JChartFX Community
  • 0

Unable to set line chart series colors




I'm unable to set the color of series using the API when JChartFX's stylesheets are included.

Simple example: if I modify the presenter.js of the example "JS_Lines_and_Stripes_Charts.zip" by adding calls to the setColor method of both series and series border (see below), the palette defaults override my API calls (so nothing happens) until I comment out the line

<link rel="stylesheet" type="text/css" href="http://www.jchartfx.com/libs/v7/current/styles/jchartfx.css"/>

 from index.html. After the removal the API calls work ok. The same behavior is seen in our app where JChartFX is embedded in. What am I doing wrong?


function LineChartWithMarkers(chart1)
// test chart series color setting


var titles = chart1.getTitles();
var title = new cfx.TitleDockable();
title.setText("Vehicles Production by Month");



Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

You are doing nothing wrong, this is by design, when you use our CSS it means colors (and fonts, and line widths) are controlled through CSS instead of API, you have 3 options

1) Do not include our palette and attributes CSS, this is recommended if you will need to control several colors "dynamically"

2) Make a copy of the used CSS and change it as needed, e.g.

.jchartfx .Attribute0 {
    fill: #D0C5E3;
    stroke: #D0C5E3;

Note that sometimes we generate several classes for an object (you can view this using Inspect in your browser), for example, axis sections generate a class such as "AxisSection AxisY_Section AxisY0_Section0" to give you a chance to change all axis sections, all Y axis sections or a particular section by index.

3) Most objects expose a setTag method that allows you to customize the generated class



Link to comment
Share on other sites

  • 0

Hi JuanC,

all right, this makes sense, thanks! I opted for a mechanism in which I create partial stylesheets dynamically and use the setTag method to override palette (in this way I can allow some of the colors to be changed by the user in the UI and at the same time allow the defaults from the palette to be used).

Btw, is there an easy way to update the series colors in the overlay user interface? Your html for it looks like this

<ul class="options second-level"><li><i class="jchartfx-icon-block" style="background-color:#57acda"></i><a class="process">Series 1</a><a class="next jchartfx-icon-arrow-right"></a></li><li><i class="jchartfx-icon-block" style="background-color:#93e24e"></i><a class="process">Series 2</a><a class="next jchartfx-icon-arrow-right"></a></li><li><i class="jchartfx-icon-block" style="background-color:#f26c5b"></i><a class="process">Series 3</a><a class="next jchartfx-icon-arrow-right"></a></li></ul>

Of course I can set these using JS, but a bit of pain because there are no class / id specifications and the color is set in style attribute.



Link to comment
Share on other sites

  • 0

I am guessing you are talking about the user interface when you select the Series menu. This is created dynamically, we do not use classes in this code but we try to get the color for AttributeX.

I noticed we do not try to use the series tag so that could explain a discrepancy between the color in the menu and the series. This has been fixed and the fix will be included in our next drop.



  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...