Date axis label visibility problem in trading view lightwight - javascript
I want to create HLOC chart with trading view lightweight. Everything is OK and I can pass data with ajax to chart.
this is my html with java scripts:
index.html
<body style="margin: 0; padding: 0; background-color: #222">
<div id="tw-container-1" style="position: absolute; width: 100%; height: 100%">
</div>
</body>
my_scripts.js
<script type="text/javascript">
const container = document.getElementById('tw-container-1');
const chart_height = window.innerHeight - 50;
const chart_width = window.innerWidth - 50;
function generateCandlestickData() {
return [
{
time: "2018-10-19",
open: 180.34,
high: 180.99,
low: 178.57,
close: 179.85,
},
{
time: "2018-10-22",
open: 180.82,
high: 181.4,
low: 177.56,
close: 178.75,
},
{
time: "2018-10-23",
open: 175.77,
high: 179.49,
low: 175.44,
close: 178.53,
},
{
time: "2018-10-24",
open: 178.58,
high: 182.37,
low: 176.31,
close: 176.97,
},
{
time: "2018-10-25",
open: 177.52,
high: 180.5,
low: 176.83,
close: 179.07,
},
{
time: "2018-10-26",
open: 176.88,
high: 177.34,
low: 170.91,
close: 172.23,
},
{
time: "2018-10-29",
open: 173.74,
high: 175.99,
low: 170.95,
close: 173.2,
},
{
time: "2018-10-30",
open: 173.16,
high: 176.43,
low: 172.64,
close: 176.24,
},
{
time: "2018-10-31",
open: 177.98,
high: 178.85,
low: 175.59,
close: 175.88,
},
{
time: "2018-11-01",
open: 176.84,
high: 180.86,
low: 175.9,
close: 180.46,
},
{
time: "2018-11-02",
open: 182.47,
high: 183.01,
low: 177.39,
close: 179.93,
},
{
time: "2018-11-05",
open: 181.02,
high: 182.41,
low: 179.3,
close: 182.19,
},
{
time: "2018-11-06",
open: 181.93,
high: 182.65,
low: 180.05,
close: 182.01,
},
{
time: "2018-11-07",
open: 183.79,
high: 187.68,
low: 182.06,
close: 187.23,
},
{
time: "2018-11-08",
open: 187.13,
high: 188.69,
low: 185.72,
close: 188.0,
},
{
time: "2018-11-09",
open: 188.32,
high: 188.48,
low: 184.96,
close: 185.99,
},
{
time: "2018-11-12",
open: 185.23,
high: 186.95,
low: 179.02,
close: 179.43,
},
{
time: "2018-11-13",
open: 177.3,
high: 181.62,
low: 172.85,
close: 179.0,
},
{
time: "2018-11-14",
open: 182.61,
high: 182.9,
low: 179.15,
close: 179.9,
},
{
time: "2018-11-15",
open: 179.01,
high: 179.67,
low: 173.61,
close: 177.36,
},
{
time: "2018-11-16",
open: 173.99,
high: 177.6,
low: 173.51,
close: 177.02,
},
{
time: "2018-11-19",
open: 176.71,
high: 178.88,
low: 172.3,
close: 173.59,
},
{
time: "2018-11-20",
open: 169.25,
high: 172.0,
low: 167.0,
close: 169.05,
},
{
time: "2018-11-21",
open: 170.0,
high: 170.93,
low: 169.15,
close: 169.3,
},
{
time: "2018-11-23",
open: 169.39,
high: 170.33,
low: 168.47,
close: 168.85,
},
{
time: "2018-11-26",
open: 170.2,
high: 172.39,
low: 168.87,
close: 169.82,
},
{
time: "2018-11-27",
open: 169.11,
high: 173.38,
low: 168.82,
close: 173.22,
},
{
time: "2018-11-28",
open: 172.91,
high: 177.65,
low: 170.62,
close: 177.43,
},
{
time: "2018-11-29",
open: 176.8,
high: 177.27,
low: 174.92,
close: 175.66,
},
{
time: "2018-11-30",
open: 175.75,
high: 180.37,
low: 175.11,
close: 180.32,
},
{
time: "2018-12-03",
open: 183.29,
high: 183.5,
low: 179.35,
close: 181.74,
},
{
time: "2018-12-04",
open: 181.06,
high: 182.23,
low: 174.55,
close: 175.3,
},
{
time: "2018-12-06",
open: 173.5,
high: 176.04,
low: 170.46,
close: 175.96,
},
{
time: "2018-12-07",
open: 175.35,
high: 178.36,
low: 172.24,
close: 172.79,
},
{
time: "2018-12-10",
open: 173.39,
high: 173.99,
low: 167.73,
close: 171.69,
},
{
time: "2018-12-11",
open: 174.3,
high: 175.6,
low: 171.24,
close: 172.21,
},
{
time: "2018-12-12",
open: 173.75,
high: 176.87,
low: 172.81,
close: 174.21,
},
{
time: "2018-12-13",
open: 174.31,
high: 174.91,
low: 172.07,
close: 173.87,
},
{
time: "2018-12-14",
open: 172.98,
high: 175.14,
low: 171.95,
close: 172.29,
},
{
time: "2018-12-17",
open: 171.51,
high: 171.99,
low: 166.93,
close: 167.97,
},
{
time: "2018-12-18",
open: 168.9,
high: 171.95,
low: 168.5,
close: 170.04,
},
{
time: "2018-12-19",
open: 170.92,
high: 174.95,
low: 166.77,
close: 167.56,
},
{
time: "2018-12-20",
open: 166.28,
high: 167.31,
low: 162.23,
close: 164.16,
},
{
time: "2018-12-21",
open: 162.81,
high: 167.96,
low: 160.17,
close: 160.48,
},
{
time: "2018-12-24",
open: 160.16,
high: 161.4,
low: 158.09,
close: 158.14,
},
{
time: "2018-12-26",
open: 159.46,
high: 168.28,
low: 159.44,
close: 168.28,
},
{
time: "2018-12-27",
open: 166.44,
high: 170.46,
low: 163.36,
close: 170.32,
},
{
time: "2018-12-28",
open: 171.22,
high: 173.12,
low: 168.6,
close: 170.22,
},
{
time: "2018-12-31",
open: 171.47,
high: 173.24,
low: 170.65,
close: 171.82,
},
{
time: "2019-01-02",
open: 169.71,
high: 173.18,
low: 169.05,
close: 172.41,
},
{
time: "2019-01-03",
open: 171.84,
high: 171.84,
low: 168.21,
close: 168.61,
},
{
time: "2019-01-04",
open: 170.18,
high: 174.74,
low: 169.52,
close: 173.62,
},
{
time: "2019-01-07",
open: 173.83,
high: 178.18,
low: 173.83,
close: 177.04,
},
{
time: "2019-01-08",
open: 178.57,
high: 179.59,
low: 175.61,
close: 177.89,
},
{
time: "2019-01-09",
open: 177.87,
high: 181.27,
low: 177.1,
close: 179.73,
},
{
time: "2019-01-10",
open: 178.03,
high: 179.24,
low: 176.34,
close: 179.06,
},
{
time: "2019-01-11",
open: 177.93,
high: 180.26,
low: 177.12,
close: 179.41,
},
{
time: "2019-01-14",
open: 177.59,
high: 179.23,
low: 176.9,
close: 178.81,
},
{
time: "2019-01-15",
open: 176.08,
high: 177.82,
low: 175.2,
close: 176.47,
},
{
time: "2019-01-16",
open: 177.09,
high: 177.93,
low: 175.86,
close: 177.04,
},
{
time: "2019-01-17",
open: 174.01,
high: 175.46,
low: 172.0,
close: 174.87,
},
]
}
// Create the Lightweight Chart within the container element
const chart = LightweightCharts.createChart(
container,
{
width: chart_width,
height: chart_height,
layout: {
background: { color: "#222" },
textColor: "#C3BCDB",
},
grid: {
vertLines: { color: "#444" },
horzLines: { color: "#444" },
},
}
);
// Setting the border color for the vertical axis
chart.priceScale().applyOptions({
borderColor: "#71649C",
});
// Setting the border color for the horizontal axis
chart.timeScale().applyOptions({
borderColor: "#71649C",
});
// Adjust the starting bar width (essentially the horizontal zoom)
chart.timeScale().applyOptions({
barSpacing: 10,
});
// Customizing the Crosshair
chart.applyOptions({
crosshair: {
// Change mode from default 'magnet' to 'normal'.
// Allows the crosshair to move freely without snapping to datapoints
mode: LightweightCharts.CrosshairMode.Normal,
// Vertical crosshair line (showing Date in Label)
vertLine: {
width: 100,
color: "#C3BCDB44",
style: LightweightCharts.LineStyle.Solid,
labelBackgroundColor: "#9B7DFF",
},
// Horizontal crosshair line (showing Price in Label)
horzLine: {
color: "#9B7DFF",
labelBackgroundColor: "#9B7DFF",
},
},
});
// Adding a window resize event handler to resize the chart when
// the window size changes.
// Note: for more advanced examples (when the chart doesn't fill the entire window)
// you may need to use ResizeObserver -> https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver
window.addEventListener("resize", () => {
chart.resize(chart_width, chart_height);
});
const trade_hloc_chart = chart.addCandlestickSeries();
trade_hloc_chart.setData(generateCandlestickData());
// Changing the Candlestick colors
trade_hloc_chart.applyOptions({
wickUpColor: "rgb(54, 116, 217)",
upColor: "rgb(54, 116, 217)",
wickDownColor: "rgb(225, 50, 85)",
downColor: "rgb(225, 50, 85)",
borderVisible: false,
});
// Adjust the options for the priceScale of the mainSeries
trade_hloc_chart.priceScale().applyOptions({
autoScale: false, // disables auto scaling based on visible content
scaleMargins: {
top: 0.1,
bottom: 0.2,
},
});
window.addEventListener('resize', () => {
chart.resize(chart_width, chart_height);
});
chart.timeScale().fitContent();
</script>
The problem is in the label of date axis: the label doesn't visible (I think the problem has been created because of z-index).
Here is screenshot of index page:
As you can see half of the date label is shown.
The version of trading view is TradingView-lightweight-3.8.0.
How can fix that? Thanks for your helps.
Related
Cannot assign to read only property 'constructor' of object '[object Object]' in g2.js
i am using angular 11 and i am using latest version of #antv/g2 and #antv/data-set package in angular 11 I do not understand why i have to encounter this error. please help me to resolve this error and thanks in advance. below is error image that i have faced. Error Image This is my code. Dashboard.component.ts import { Chart } from '#antv/g2'; var DataSet = require('#antv/data-set'); ngAfterViewInit() { // TODO: const chart1 = this.genChart1(); const chart2 = this.genChart2(); // NOTE: this.settings.notice.subscribe(res => { chart1.forceFit(); chart2.forceFit(); }); } // Line chart genChart1() { const data = [ { date: '2019-6-24', indicator: 'UV', count: 7 }, { date: '2019-6-24', indicator: 'Download', count: 3.9 }, { date: '2019-6-25', indicator: 'UV', count: 6.9 }, { date: '2019-6-25', indicator: 'Download', count: 4.2 }, { date: '2019-6-26', indicator: 'UV', count: 9.5 }, { date: '2019-6-26', indicator: 'Download', count: 5.7 }, { date: '2019-6-27', indicator: 'UV', count: 14.5 }, { date: '2019-6-27', indicator: 'Download', count: 8.5 }, { date: '2019-6-28', indicator: 'UV', count: 18.4 }, { date: '2019-6-28', indicator: 'Download', count: 11.9 }, { date: '2019-6-29', indicator: 'UV', count: 21.5 }, { date: '2019-6-29', indicator: 'Download', count: 15.2 }, { date: '2019-6-30', indicator: 'UV', count: 25.2 }, { date: '2019-6-30', indicator: 'Download', count: 17 }, { date: '2019-7-1', indicator: 'UV', count: 26.5 }, { date: '2019-7-1', indicator: 'Download', count: 16.6 }, { date: '2019-7-2', indicator: 'UV', count: 23.3 }, { date: '2019-7-2', indicator: 'Download', count: 14.2 }, { date: '2019-7-3', indicator: 'UV', count: 18.3 }, { date: '2019-7-3', indicator: 'Download', count: 10.3 }, { date: '2019-7-4', indicator: 'UV', count: 13.9 }, { date: '2019-7-4', indicator: 'Download', count: 6.6 }, { date: '2019-7-5', indicator: 'UV', count: 9.6 }, { date: '2019-7-5', indicator: 'Download', count: 4.8 }, ]; // const chart = new G2.Chart({ const chart = new Chart({ container: 'chart1', forceFit: true, height: 300, padding: [20, 20, 80, 50], }); chart.source(data, { date: { alias: '', type: 'time', mask: 'MM-DD', }, }); chart.tooltip({ crosshairs: { type: 'line', }, }); chart.axis('count', { label: { formatter: function formatter(val) { return val + 'K'; }, }, }); chart .line() .position('date*count') .color('indicator'); chart .point() .position('date*count') .color('indicator') .size(4) .shape('circle') .style({ stroke: '#fff', lineWidth: 1, }); chart.render(); return chart; } // Pie chart genChart2() { const text = ['MIDNIGHT', '3 AM', '6 AM', '9 AM', 'NOON', '3 PM', '6 PM', '9 PM']; const data = []; for (let i = 0; i < 24; i++) { const item: any = {}; item.type = i + ''; item.value = 10; data.push(item); } const DataView = DataSet.DataView; const dv = new DataView(); dv.source(data).transform({ type: 'percent', field: 'value', dimension: 'type', as: 'percent', }); // const chart = new G2.Chart({ const chart = new Chart({ container: 'chart2', forceFit: true, height: 300, padding: 50, }); chart.legend(false); chart.tooltip({ showTitle: false, }); const bgView: any = chart.view(); bgView.coord('theta', { innerRadius: 0.9, }); bgView.source(dv); bgView .intervalStack() .position('percent') .color('type', ['rgba(255, 255, 255, 0)']) .style({ stroke: '#444', lineWidth: 1, }) .tooltip(false) .select(false); bgView.guide().text({ position: ['50%', '50%'], content: '24 hours', style: { lineHeight: '240px', fontSize: '30', fill: '#262626', textAlign: 'center', }, }); const intervalView = chart.view(); intervalView.source(data); intervalView.coord('polar', { innerRadius: 0.9, }); intervalView.axis(false); intervalView .interval() .position('type*value') .size('type', val => { if (val % 3 === 0) { return 4; } else { return 0; } }) .color('#444') .tooltip(false) .label('type', val => { if (val % 3 === 0) { return text[val / 3]; } return ''; }); const userData = [ { type: 'A', value: 60 }, { type: 'B', value: 10 }, { type: 'C', value: 10 }, { type: 'D', value: 40 }, { type: 'E', value: 20 }, { type: 'F', value: 10 }, { type: 'G', value: 30 }, { type: 'H', value: 30 }, ]; const userDv = new DataView(); userDv.source(userData).transform({ type: 'percent', field: 'value', dimension: 'type', as: 'percent', }); const pieView = chart.view(); pieView.source(userDv, { percent: { formatter: function formatter(val) { return (val * 100).toFixed(2) + '%'; }, }, }); pieView.coord('theta', { innerRadius: 0.75, }); pieView .intervalStack() .position('percent') .color('type') .label('type', { offset: 40, }) .select(false); chart.render(); return chart; } Dashboard.component.html <div class="matero-row" fxLayout="row wrap"> <!-- Charts --> <div class="matero-col" fxFlex.gt-sm="60" fxFlex="100"> <mat-card> <mat-card-subtitle>Traffic</mat-card-subtitle> <mat-card-content> <div id="chart1"></div> </mat-card-content> </mat-card> </div> <div class="matero-col" fxFlex.gt-sm="40" fxFlex="100"> <mat-card> <mat-card-subtitle>User Behavier</mat-card-subtitle> <mat-card-content> <div id="chart2"></div> </mat-card-content> </mat-card> </div> </div> please help me.
You can't assign a constructor here : const DataView = DataSet.DataView; const dv = new DataView(); According to the docs : const dv0 = new DataSet.DataView();
Adding style to div element in React ParticleJS
I am trying to add style to the div element which gets created while adding particle component in React. I am adding the style in Component and not in the options params provided by tsparticles. But the height and visibility properties is getting added to the canvas. Please see attached screenshot in the post. <Particles className="react-particles" id="particles-js" style={ { visibility: "hidden" } } options={{ background: { color: { value: "#3e1110" }, }, fpsLimit: 60, interactivity: { detectsOn: "canvas", events: { onClick: { enable: false, mode: "push", }, onHover: { enable: false, mode: "repulse" }, resize: true }, modes: { bubble: { distance: 400, duration: 2, opacity: 0.8, size: 40, }, push: { quantity: 4, }, repulse: { distance: 200, duration: 0.4 } } }, canvas:{ w: "500", h: "500" }, particles: { number: { value: 40, density: { enable: true, value_area: 800 } }, color: { value: "#722035" }, shape: { type: "edge", stroke: { width: 0, color: "#000000" }, polygon: { "nb_sides": 5 }, image: { src: "img/github.svg", width: 50, height: 50 } }, opacity: { value: 0.749690259550659, random: true, anim: { enable: false, speed: 1, opacity_min: 0.1, sync: false } }, size: { value: 5, random: true, anim: { enable: false, speed: 3, size_min: 1, sync: false } }, line_linked: { enable: false, distance: 150, color: "#ffffff", opacity: 0.4, width: 1 }, move: { enable: true, speed: 3, direction: "top-right", random: true, straight: false, out_mode: "out", bounce: false, attract: { enable: false, rotateX: 600, rotateY: 1200 } } }, interactivity: { detect_on: "canvas", events: { onhover: { enable: false, mode: "repulse" }, onclick: { enable: false, mode: "push" }, resize: true }, modes: { grab: { distance: 400, line_linked: { opacity: 1 } }, bubble: { distance: 400, size: 40, duration: 2, opacity: 8, speed: 3 }, repulse: { distance: 200, duration: 0.4 }, push: { particles_nb: 4 }, remove: { particles_nb: 2 } } }, detectRetina: true, }} />
Adding TSParticles params in React Particle
I am trying to replicate ts particle params to use in React particles. I used the same params what are working in tsparticles, But in React it is not getting displayed. Here are the below config params for both TsParticle and React Particle. TSParticles particles: { number: { value: 10, density: { enable: true, value_area: 9999999 } }, color: { value: "#ffffff" }, shape: { type: "square", stroke: { width: 0, color: "#000000" }, image: { src: "img/github.svg", width: 50, height: 50 } }, opacity: { value: 1, random: true, anim: { enable: true, speed: 1, opacity_min: 0, sync: false } }, size: { value: 3, random: true, anim: { enable: false, speed: 4, size_min: 0.3, sync: false } }, line_linked: { enable: false, distance: 150, color: "#ffffff", opacity: 0.4, width: 1 }, move: { enable: true, speed: 0.5, direction: "bottom-right", random: true, straight: false, out_mode: "out", bounce: false, attract: { enable: false, rotateX: 600, rotateY: 600 } } }, interactivity: { detect_on: "canvas", events: { resize: true }, modes: { grab: { distance: 191.80819180819182, line_linked: { opacity: 1 } }, bubble: { distance: 250, size: 0, duration: 2, opacity: 0, speed: 3 }, repulse: { distance: 695.3046953046953, duration: 0.4 }, push: { particles_nb: 4 }, remove: { particles_nb: 2 } } }, React Particles particles: { number: { value: 10, density: { enable: true, value_area: 99999 } }, color: { value: "#ffffff" }, shape: { type: "square", stroke: { width: 0, color: "#000000" }, image: { src: "img/github.svg", width: 50, height: 50 } }, opacity: { value: 1, random: true, anim: { enable: true, speed: 1, opacity_min: 0, sync: false } }, size: { value: 3, random: true, anim: { enable: false, speed: 4, size_min: 0.3, sync: false } }, move: { enable: true, speed: 0.5, direction: "top-left", random: true, straight: false, out_mode: "out", bounce: false, attract: { enable: false, rotateX: 600, rotateY: 600 } }, interactivity: { detect_on: "canvas", events: { resize: true } }, }, Link for both TsParticles and React Particles TSParticle React Particle
Highcharts Stacked Range z-Index
Looking at this script: (JsFiddle isn't displaying the graphs for me, for some reason, but it works as html) I have two overlapping ranges but I'm unable to have one pair bring blue to the front, the other black. Click on 'Task 2' to see that the above blue range is hidden. I've tried using the z-index option but I can only set it by series not by pair. Full code: <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> <script src="http://code.highcharts.com/highcharts.js"></script> <script src="http://code.highcharts.com/highcharts-more.js"></script> <script src="http://code.highcharts.com/modules/exporting.js"></script> <div id="container1" style="min-width: 400px; height: 200px; margin: 0 auto"></div> <div id="container2" style="min-width: 400px; height: 200px; margin: 0 auto"></div> <script> $(function () { window.chart1 = new Highcharts.Chart({ chart: { renderTo: 'container1', type: 'columnrange', inverted: true }, title: { text: "Top Chart" }, xAxis: { categories: ['Customer A', 'Customer B'] }, yAxis: { labels: { formatter: function () { return Math.abs(this.value); } } }, tooltip: { formatter: function () { return '<b>' + this.series.name + ', age ' + this.point.category + '</b><br/>' + 'Population: ' + Highcharts.numberFormat(Math.abs(this.point.y), 0); } }, legend: { enabled: true }, plotOptions: { columnrange: { grouping: false } }, series: [{ name: 'Task 1', stack: 'Tasks', data: [{ x: 0, low: -5, high: 5 }, { x: 1, low: -15, high: 15 }] }, { name: 'Task 2', stack: 'Tasks', data: [{ x: 0, low: -10, high: 10 }, { x: 1, low: -3, high: 3 }] }] }); }); </script>
One of the way for achieving this is to provide pointPadding to specific series in charts. This option allows both bars to be visible even it is overlapping each other. plunker demo series: [{ name: 'Task 1', stack: 'Tasks', data: [{ x: 0, low: -5, high: 5 }, { x: 1, low: -15, high: 15 }] }, { name: 'Task 2', stack: 'Tasks', pointPadding: 0.3, /*pointPadding to specific series*/ data: [{ x: 0, low: -10, high: 10 }, { x: 1, low: -3, high: 3 }] }]
How to change the onClick function of C3 load function
I am trying to update a C3 graph with different onclick funtion by using the load function of C3. The code snippet is here: var json1 = [{ date: '2014-01-01', upload: 200, download: 200, total: 400 }, { date: '2014-01-02', upload: 100, download: 300, total: 400 }, { date: '2014-02-01', upload: 300, download: 200, total: 500 }, { date: '2014-02-02', upload: 400, download: 100, total: 500 }]; var json2 = [{ date: '2014-01-01', upload: 200, download: 500, total: 700 }, { date: '2014-01-02', upload: 500, download: 450, total: 950 }, { date: '2014-02-01', upload: 200, download: 800, total: 1000 }, { date: '2014-02-02', upload: 300, download: 500, total: 800 }]; var chart = c3.generate({ bindto: '#div1', data: { json: json1, onclick: function (event) { console.log("11111111111") ; }, keys: { x: 'date', value: ['upload', 'download'] } }, axis: { x: { type: 'timeseries', tick: { format: function (x) { if (x.getDate() === 1) { return x.toLocaleDateString(); } } } } } }); setTimeout(function () { chart.unload(); }, 1000); setTimeout(function () { chart.load({ json: json2, keys: { x: 'date', value: ['upload', 'download'] }, onclick: function (event) { console.log("22222222") ; }, }); }, 1000); <link href="https://rawgit.com/masayuki0812/c3/master/c3.css" rel="stylesheet"/> <script src="https://rawgit.com/masayuki0812/c3/master/c3.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.10/d3.min.js"></script> <div id="div1"></div> Please tell me a way so to update the onClick funtion on the load function itself.
From what I can find, c3.load() does not offer all the elements of c3.generate(), therefore you have 2 ways of doing this. Reuse c3.generate(), or hand off the click event to a variable that you can change, such as: // INITIAL CLICK HANDLER var clickhandler = function(event) { console.log("11111111111"); } var json1 = [{ date: '2014-01-01', upload: 200, download: 200, total: 400 }, { date: '2014-01-02', upload: 100, download: 300, total: 400 }, { date: '2014-02-01', upload: 300, download: 200, total: 500 }, { date: '2014-02-02', upload: 400, download: 100, total: 500 }]; var json2 = [{ date: '2014-01-01', upload: 200, download: 500, total: 700 }, { date: '2014-01-02', upload: 500, download: 450, total: 950 }, { date: '2014-02-01', upload: 200, download: 800, total: 1000 }, { date: '2014-02-02', upload: 300, download: 500, total: 800 }]; // GENERATE CHART FROM JSON1 var chart = c3.generate({ bindto: '#div1', data: { json: json1, onclick: function(event) { clickhandler(event) }, keys: { x: 'date', value: ['upload', 'download'] } }, axis: { x: { type: 'timeseries', tick: { format: function (x) { if (x.getDate() === 1) { return x.toLocaleDateString(); } } } } } }); // MAKE CHANGES TO THE LOADED CHART setTimeout(function () { // CHANGE THE CLICK EVENT HANDLER clickhandler = function(event) { console.log('22222222222'); }; // UNLOAD EXISTING DATA AND LOAD NEW DATA FROM JSON2 chart.load({ json: json2, keys: { x: 'date', value: ['upload', 'download'] }, unload: chart.columns }); }, 1000); <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script> <link href="https://cdnjs.cloudflare.com/ajax/libs/c3/0.4.11/c3.css" rel="stylesheet"/> <script src="https://cdnjs.cloudflare.com/ajax/libs/c3/0.4.11/c3.js"></script> <div id="div1"></div>