在ChartJS工具提示值前面添加文本

时间:2019-01-18 06:36:26

标签: javascript chart.js

我想在ChartJS呈现的工具提示值之前添加一个文本,在本例中为现金价值处的货币符号。以下是我的代码

$cashflow_tabs[] = array(
		'tab_name' => 'cashflow Stats',
		'tab_content' => ' <canvas id="cashflow_usage-' . get_the_ID() . '" height="80"></canvas>',
		'tab_js' => '<script type="text/javascript">
				var ctx = document.getElementById(\'cashflow_usage-' . get_the_ID() . '\').getContext(\'2d\');
				var cashflow_usage = new Chart(ctx, {
				type: \'bar\',
				data: {
						labels: ["' . $last_5mth_label . '", "' . $last_4mth_label . '", "' . $last_3mth_label . '", "' . $last_2mth_label . '", "' . $last_mth_label . '", "' . $current_mth_label . '"],
						datasets: [{
								label: "Cash In",
								backgroundColor: ["#0f8fff","#0f8fff","#0f8fff","#0f8fff","#0f8fff","#0f8fff"],
                borderWidth: 1,
								data: ['. $Last_5mth_cash_in .','. $last_4mth_cash_in .','. $last_3mth_cash_in .','. $last_2mth_cash_in .','. $last_mth_cash_in .','. $current_cash_in .'],
					 }, {
               label: "Cash Out",
               backgroundColor: ["#cccccc","#cccccc","#cccccc","#cccccc","#cccccc","#cccccc"],
               borderWidth: 1,
               data: ['. $Last_5mth_cash_out .','. $last_4mth_cash_out .','. $last_3mth_cash_out .','. $last_2mth_cash_out .','. $last_mth_cash_out .','. $current_cash_out .'],
          }]},
						options: {
              barValueSpacing: 20,
							title: { display: false, text: "Past Tasks & Performance Trends", position: "bottom" },
							legend : { position: "bottom", display: false, labels:{lineWidth:3}  },
							scales : {
                xAxes: [{ stacked: false, gridLines: { drawBorder: false, display: false }, ticks: {  beginAtZero: true } }],
							  yAxes: [{ stacked: false, gridLines: { drawBorder: false, display: false }, ticks: { display: false } }]
                },
				}
		});
		</script>',
  );

enter image description here

0 个答案:

没有答案