Dhtmlxchart showSeries() and hideSeries

Using DHTMLX v3.6

I created a line chart and added several series to it. After the chart is rendered, I am hoping to provide a set of checkboxes to the right of the chart which will represent each of the added series which can be checked/unchecked and eventually hide or show respective series in the chart.

I believe DHX also provides a similar feature when using legend’s toggle property but I do not want the legend items disappear upon clicking. Hence I opted to create a custom legend section with 5 checkboxes representing each of the 5 series I added in the chart using addSeries() function and hopefully use the hideSeries(index) and showSeries(index) methods of the dhtmlxchart to toggle between showing and hiding each series but keeping the legend items visible.

I attempted to pass index values ‘0’ to ‘4’ in the showSeries(index) and hideSeries(index) functions to toggle visibility of the 5 series I added but for some reason it does not work. Will the series index be the same order it was added to the chart? Thanks.

Below is my script to create the dhtml chart and another function I call to hide/show series…

var dhxTrendChart;

//Function to create dhtmlx chart; added with 6 line series
function loadTrendChart()
{
var trend_data = [
{ “Month”:“Aug”, “Actual”:“40.00”, “Target”:“76.50”, “Chain”:“60.00”, “Operation”:“50.00”, “Market”:“10.00”, “District”:“30.00” },
{ “Month”:“Sep”, “Actual”:“40.00”, “Target”:“76.50”, “Chain”:“60.00”, “Operation”:“50.00”, “Market”:“10.00”, “District”:“30.00” },
{ “Month”:“Oct”, “Actual”:“40.00”, “Target”:“76.50”, “Chain”:“60.00”, “Operation”:“50.00”, “Market”:“10.00”, “District”:“30.00” },
{ “Month”:“Nov”, “Actual”:“40.00”, “Target”:“76.50”, “Chain”:“60.00”, “Operation”:“50.00”, “Market”:“10.00”, “District”:“30.00” },
{ “Month”:“Dec”, “Actual”:“40.00”, “Target”:“76.50”, “Chain”:“60.00”, “Operation”:“50.00”, “Market”:“10.00”, “District”:“30.00” },
{ “Month”:“Jan”, “Actual”:“40.00”, “Target”:“76.50”, “Chain”:“60.00”, “Operation”:“50.00”, “Market”:“10.00”, “District”:“30.00” },
{ “Month”:“Feb”, “Actual”:“40.00”, “Target”:“76.50”, “Chain”:“60.00”, “Operation”:“50.00”, “Market”:“10.00”, “District”:“30.00” },
{ “Month”:“Mar”, “Actual”:“40.00”, “Target”:“76.50”, “Chain”:“60.00”, “Operation”:“50.00”, “Market”:“10.00”, “District”:“30.00” },
{ “Month”:“Apr”, “Actual”:“40.00”, “Target”:“76.50”, “Chain”:“60.00”, “Operation”:“50.00”, “Market”:“10.00”, “District”:“30.00” },
{ “Month”:“May”, “Actual”:“40.00”, “Target”:“76.50”, “Chain”:“60.00”, “Operation”:“50.00”, “Market”:“10.00”, “District”:“30.00” },
{ “Month”:“Jun”, “Actual”:“40.00”, “Target”:“76.50”, “Chain”:“60.00”, “Operation”:“50.00”, “Market”:“10.00”, “District”:“30.00” },
{ “Month”:“Jul”, “Actual”:“40.00”, “Target”:“76.50”, “Chain”:“60.00”, “Operation”:“50.00”, “Market”:“10.00”, “District”:“30.00” }
];

dhxTrendChart = new dhtmlXChart(
{
view: “line”,
container: “dhxTrendChartDiv”,
padding:
{
top: 10,
bottom: 15
},
xAxis:
{
template: “#Month#”,
lines: false,
color: “#A6A6A6
},
yAxis:
{
template: function(val)
{
return “” + val + “%
},
color: “#A6A6A6
},
legend:{
layout:“y”,
align:“right”,
valign:“middle”,
width:0,
toggle:false,
values:[

]
}
});

dhxTrendChart.addSeries(
{
value: “#Actual#”,
tooltip:
{
template: “#Actual#”
},
line:
{
color: “#0000A0”,
width: 2
},
item:
{
radius:1,
borderColor: “#0000A0”,
color: “#0000A0” /,
type: “circle”
/
}
});

dhxTrendChart.addSeries(
{
value: “#Target#”,
tooltip:
{
template: “#Target#”
},
line:
{
color: “#000000”,
width: 2
},
item:
{
radius:1,
borderColor: “#000000”,
color: “#000000” /,
type: “square”
/
}
});

dhxTrendChart.addSeries(
{
value: “#Chain#”,
tooltip:
{
template: “#Chain#”
},
line:
{
color: “#b25151”,
width: 2
},
item:
{
radius:1,
borderColor: “#b25151”,
color: “#b25151” /,
type: “triangle”
/
}
});

dhxTrendChart.addSeries(
{
value: “#Operation#”,
tooltip:
{
template: “#Operation#”
},
line:
{
color: “#FF7F50”,
width: 2
},
item:
{
radius:1,
borderColor: “#FF7F50”,
color: “#FF7F50” /,
type: “diamond”
/
}
});

dhxTrendChart.addSeries(
{
value: “#Market#”,
tooltip:
{
template: “#Market#”
},
line:
{
color: “#008B8B”,
width: 2
},
item:
{
radius:1,
borderColor: “#008B8B”,
color:“#008B8B” /,
type: “square”
/
}
});

dhxTrendChart.addSeries(
{
value: “#District#”,
tooltip:
{
template: “#District#”
},
line:
{
color: “#6A5ACD”,
width: 2
},
item:
{
radius:1,
borderColor: “#6A5ACD”,
color: “#6A5ACD” /*,
type: “triangle” */
}
});

dhxTrendChart.parse( trend_data, “json” );

}

//Function to be called on check/uncheck of 6 checkboxes named ‘1’ to ‘6’ to hopefully hide/show series in the dhtml chart with 6 line series;
function showHideSeries( clickedIndicatorObj )
{
if ( clickedIndicatorObj.checked )
{
dhxTrendChart.showSeries(parseInt(clickedIndicatorObj.name) - 1);
}
else
{
dhxTrendChart.hideSeries(parseInt(clickedIndicatorObj.name) - 1);
}
}

but I do not want the legend items disappear upon clicking
Actually it must be just grayed out, not removed

Indexes will be in the same order as you have added them, but they are 1 based ( so indexes will be 1 - 6 )

//works as expected dhxTrendChart.hideSeries(1)

Thanks Stanislav!

How do you match a legend with a series? Meaning when I click on a legend, how does dhtmlx match which series to toggle (hide/show)? Should I simply define values in my legend and assume that it will be tied/match to the same sequence the series were added? Thanks again!

I have added the legends below to the same script I initially attached to hopefully toggle the same 6 series I added.

legend:{
layout:“y”,
align:“right”,
valign:“middle”,
width:120,
toggle:true,
values:[
{text:“Actual”,color:"#0000A0"},
{text:“Target”,color:"#000000"},
{text:“Chain”,color:"#b25151"},
{text:“Operation”,color:"#FF7F50"},
{text:“Market”,color:"#008B8B"},
{text:“District”,color:"#6A5ACD"}
]

Yes, it assign legend items to the series in the same order as they was attached.
But there is a problem with your code ( maybe it is a problem in our API though )

It is expected that first chart is defined directly in dhtmlxChart constructor and addSeries are used to add extra series ( 2nd and next ), but you are not defining any data rendering rules in the constructor but adds all of series through addSeries command.

Please check the updated code, with such init it works as expected.
( we may fix charts code to allow the same way of initialization as was in your original code )
01_load_xml.zip (1.41 KB)

Thanks Stanislav!

I am also having issues when rendering the chart on IE6. Is the dhtmlx chart fully supported in this browser version? For some reason, when rendering the graph (for the same script above), the Y axis start mid way of the chart width. Please see attached screens which were rendered using IE6, IE8 and Safari 5.0.2.
DHTMLx Chart Issue on IE 6.zip (45.8 KB)

Please try to use css libraries from the attached package.
libs.zip (77.5 KB)

Hello. We are encountering some issue with using DHTMLx line chart where in not all data points can be seen even if the JSON data is complete. For the sample JSON data below, 95.5 data point does not show while the 80 shows up.

var trend_data = [
{"Month":"Jan","Target":"null","Actual":"null"},
{"Month":"Feb","Target":"null","Actual":"null"},
{"Month":"Mar","Target":"null","Actual":"null"},
{"Month":"Apr","Target":"null","Actual":"null"},
{"Month":"May","Target":"null","Actual":"null"},
{"Month":"Jun","Target":"null","Actual":"null"},
{"Month":"Jul","Target":"null","Actual":"null"},
{"Month":"Aug","Target":"null","Actual":"null"},
{"Month":"Sep","Target":"null","Actual":"null"},
{"Month":"Oct","Target":"null","Actual":"null"},
{"Month":"Nov","Target":"null","Actual":"null"},
{"Month":"Dec","Target":"80.0","Actual":"95.5"}
];

We were initially not passing values for yAxis - start, step and end attributes and letting DHTMLx provide these for us since we do not want a fixed range of y-Axis range and intervals. For some reason, not all data points can be displayed.

        yAxis:
        {        
	        template: function(val)
	        {
		        return "<span style='font-size: 8pt;'>" + val + "%</span>"
		    },
	        color: "#A6A6A6"
        }

We noticed that when we provide a fixed/static start and end values it all our data points show but with this we lose the feature of having a dynamic y-Axis start/end ranges (unless we implement our own logic to compute/provide dynamic values based on set of data).

        yAxis:
        {
	        start: 70,
	        step: 10,
	        end: 100,
	        template: function(val)
	        {
		        return "<span style='font-size: 8pt;'>" + val + "%</span>"
		    },
	        color: "#A6A6A6"
                 }   

Below is a more complete code snippet for the problem. Is this a known issue with a different work around?

window.onload = function()
{
var trend_data = [
{“Month”:“Jan”,“Target”:“null”,“Actual”:“null”},
{“Month”:“Feb”,“Target”:“null”,“Actual”:“null”},
{“Month”:“Mar”,“Target”:“null”,“Actual”:“null”},
{“Month”:“Apr”,“Target”:“null”,“Actual”:“null”},
{“Month”:“May”,“Target”:“null”,“Actual”:“null”},
{“Month”:“Jun”,“Target”:“null”,“Actual”:“null”},
{“Month”:“Jul”,“Target”:“null”,“Actual”:“null”},
{“Month”:“Aug”,“Target”:“null”,“Actual”:“null”},
{“Month”:“Sep”,“Target”:“null”,“Actual”:“null”},
{“Month”:“Oct”,“Target”:“null”,“Actual”:“null”},
{“Month”:“Nov”,“Target”:“null”,“Actual”:“null”},
{“Month”:“Dec”,“Target”:“80.0”,“Actual”:“95.5”}
];

dhxTrendChart =  new dhtmlXChart(
{
    view: "line",
    container: "dhxTrendChartDiv",    
	padding:
	{
		top: 10,
		bottom: 15
	},
    xAxis:
    {
        template: "<span style='font-size: 8pt;'>#Month#</span>",
        lines: false,
        color: "#A6A6A6"
    },
    yAxis:
    {
        start: 70,
        step: 10, -- will show both data points if this line is commented out
        end: 100,	        
        template: function(val)
        {
	        return "<span style='font-size: 8pt;'>" + val + "%</span>"
	    },
        color: "#A6A6A6"
    },
    legend:
    {
		layout:"y",
		align:"right",
		valign:"middle",
		width:1,
		values:[    
		]
	}	     		               
});

dhxTrendChart.addSeries(
{
    value: "#Actual#",
    line:
    {
        color: actualTrendColor,
        width: 2
    },
    item:
    {
        radius:1,
        borderColor: actualTrendColor,
        color: actualTrendColor
    }	        
});	

dhxTrendChart.addSeries(
{
    value: "#Target#",
    line:
    {
        color: targetTrendColor,
        width: 2
    },
    item:
    {
        radius:1,
        borderColor: targetTrendColor,
        color: targetTrendColor
    }		        
});	

dhxTrendChart.parse( trend_data, "json" );

}

Hello, derik2r
Could you prvide us completed demo, not a code snippets to reproduce your issue?
docs.dhtmlx.com/doku.php?id=othe … leted_demo

Please see attached demo. Thanks.
DHTMLx Support Inquiry.zip (20.1 KB)
Completed Demo.zip (264 KB)

Hello. If I may add, looks like the temporary work around we used does not work for ALL other possible combinations of data points. If you use this JSON data in the previously sent demo, even with the yAxis step attribute commented out, one data point (59.0) will not show up.

var companies=[
{ “companyA”:“null”, “companyB”:“null”, “month”:“Jan” },
{ “companyA”:“null”, “companyB”:“null”, “month”:“Feb” },
{ “companyA”:“null”, “companyB”:“null”, “month”:“Mar” },
{ “companyA”:“null”, “companyB”:“null”, “month”:“Apr” },
{ “companyA”:“null”, “companyB”:“null”, “month”:“May” },
{ “companyA”:“null”, “companyB”:“null”, “month”:“Jun” },
{ “companyA”:“null”, “companyB”:“null”, “month”:“Jul” },
{ “companyA”:“null”, “companyB”:“null”, “month”:“Aug” },
{ “companyA”:“null”, “companyB”:“null”, “month”:“Sep” },
{ “companyA”:“null”, “companyB”:“null”, “month”:“Oct” },
{ “companyA”:“null”, “companyB”:“null”, “month”:“Nov” },
{ “companyA”:“59.0”, “companyB”:“80.0”, “month”:“Dec” }];

What browser and OS do you have?

I am currently using Windows XP and IE 8. Thanks.

Please, check attached sample locally.
It works on our side in the same system conditions.
chart.rar (87.4 KB)

Hello. Thanks for your response. I think the issue is with specific values or combination of data points, which you did not use in your example to replicate the same problem we encountered. Please try to replace your data with below example. Since our application will only start showing data for December, we do not have historical data for prior months, hence this will be the structure of our JSON.

var companies=[
{ “companyA”:“null”, “companyB”:“null”, “month”:“Jan” },
{ “companyA”:“null”, “companyB”:“null”, “month”:“Feb” },
{ “companyA”:“null”, “companyB”:“null”, “month”:“Mar” },
{ “companyA”:“null”, “companyB”:“null”, “month”:“Apr” },
{ “companyA”:“null”, “companyB”:“null”, “month”:“May” },
{ “companyA”:“null”, “companyB”:“null”, “month”:“Jun” },
{ “companyA”:“null”, “companyB”:“null”, “month”:“Jul” },
{ “companyA”:“null”, “companyB”:“null”, “month”:“Aug” },
{ “companyA”:“null”, “companyB”:“null”, “month”:“Sep” },
{ “companyA”:“null”, “companyB”:“null”, “month”:“Oct” },
{ “companyA”:“null”, “companyB”:“null”, “month”:“Nov” },
{ “companyA”:“80”, “companyB”:“95.5”, “month”:“Dec” }

];

Then replace the yAxis parameters with below values for ‘start’, ‘step’ and ‘end’ attributes:

		yAxis:{
			start:70,
			step:10,
			end:100,
			template:function(value){
			    return value%5?"":value
			}
		},

This SPECIFIC example, shows the 80 data point for companyA but does not show the 95.5 data point for companyB. I dont think that DHTMLx line chart only supports whole numbers since if I change the 95.5 data point for companyB to 94.5, the chart will show both 80 and 94.5 (but not 80 and 95.5).

Attached is the same chart.rar you provided with the above SPECIFIC sample data plugged in.

Thanks!
chart.zip (93.3 KB)

Here is a fix for in attachment
13.11.11.rar (70 KB)