react-chartjs-2 icon indicating copy to clipboard operation
react-chartjs-2 copied to clipboard

Graphing multiple datasets on parallel axes

Open boriskogan81 opened this issue 8 years ago • 2 comments

I'm trying to graph two different kinds of dataset as lines on one chart. Both share an X-axis (week of the year) but have different Y-axes; the first has a categorical Y-axis (stage of development) and the second has a linear Y-axis (Brix value, a number from 0-30.)

The first kind of dataset shows up, the second doesn't. I can see its label on top of the chart, but the data is not graphed.

Here's how the first kind of dataset is built:

{
	label: title,
	labels: data,
	fill: false,
	lineTension: 0.1,
	borderColor: colorArray()[counter],
	borderCapStyle: 'butt',
	borderJoinStyle: 'miter',
	pointBorderColor: 'rgba(75,192,192,1)',
	pointBackgroundColor: '#fff',
	pointBorderWidth: 1,
	pointHoverRadius: 6,
	pointHoverBackgroundColor: 'rgba(75,192,192,1)',
	pointHoverBorderColor: 'rgba(220,220,220,1)',
	pointHoverBorderWidth: 3,
	pointRadius: 1,
	pointHitRadius: 1,
	showLine: true,
	steppedLine: true,
	spanGaps: true,
	data: data,
	year: dataYear,
	measurement: 'state'
};

Here's how the second kind is built:

{
	label: title,
	labels: brixLabelArray,
	fill: false,
	lineTension: 0.1,
	borderColor: colorArray()[counter],
	borderCapStyle: 'butt',
	borderJoinStyle: 'miter',
	pointBorderColor: 'rgba(75,192,192,1)',
	pointBackgroundColor: '#fff',
	pointBorderWidth: 1,
	pointHoverRadius: 1,
	pointHoverBackgroundColor: 'rgba(75,192,192,1)',
	pointHoverBorderColor: 'rgba(220,220,220,1)',
	pointHoverBorderWidth: 6,
	pointRadius: 3,
	pointHitRadius: 1,
	showLine: true,
	steppedLine: false,
	spanGaps: true,
	data: data,
	year: dataYear,
	measurement: 'Brix'
}

Here's how I'm building the options object:

{
	legend: {
		display: true
	},
	scales: {
		xAxes: [
			{
				scaleLabel: {
					display: true,
					labelString: 'Weeks'
				},
				ticks: {
					autoSkip: true,
					autoSkipPadding: 20
				}
			}
		],
		yAxes: [
			{
				type: 'category',
				labels: this.state.eventLabelArray
			},
			{
				type: 'linear',
				labels: this.state.brixLabelArray
			}
		]
	}
};

And here is how I put it all together:

const data = {
	labels: this.state.eventWeekArray,
	datasets: datasets
};

<Line data={data} options={options} />

And here is what it looks like. You can see the Brix data is showing up as a label, but not being charted:

image

boriskogan81 avatar Jan 16 '18 19:01 boriskogan81

Any fix for this issue ?

Prasad-YS avatar Jun 12 '19 05:06 Prasad-YS

Closing for now. Please supply a sandbox or code example with the latest versions of both libraries. If the problem persists, feel free to open a new issue.

pringelmann avatar Dec 10 '19 18:12 pringelmann