HighCharts -- MVC 3 数据库

2024-02-18

我正在 Visual Studio 2010 中使用 DotNet.Highcharts。我正在创建一个 MVC 3 Web 应用程序。我可以通过静态分配数据来使 HighCharts 工作。我希望能够将数据从数据库发送到 HighCharts 进行显示。

我可以创建一个类来控制数据,然后将该类发送到 HighCharts 吗?如果是这样,谁能告诉我该怎么做?另外,如果有人有一个可以证明这一点并且愿意分享的工作项目,那就太棒了。

我看到有人在另一个问题中发布了以下课程。但是,我不知道如何使用它或将类发送到 HighCharts 脚本。任何帮助将不胜感激。

class HighChartsPoint
{
    public double x {set; get;}
    public double y {set; get;}
    public string color {set; get;}
    public string id {set; get;}
    public string name {set; get;}
    public bool sliced {set; get;}
} 

EDIT

好吧,我正在构建一个 Web 应用程序来显示从太阳能监测收集的数据中的信息。因此,它将是按组合器、逆变器等分组的功率、电压、电流等。我相信这将是 X 和 Y 数据。但是,如果通过对象数组进行编码会更简单,那么我完全赞成。我希望这回答了你的问题。以下是我的数据模型类。我还没有完全摆脱它们。我仍然需要添加验证并更改链接到其他表的字段。要将 power_string 类中的combiner_id 字段链接到power_combiner 类中的id 字段,我将使用: public virtual power_combinercombiner_id { get;放; }

public class AESSmartEntities : DbContext
{
    public DbSet<power_combiner> PowerCombiners { get; set; }
    public DbSet<power_combinerhistory> PowerCombinerHistorys { get; set; }
    public DbSet<power_coordinator> PowerCoordinators { get; set; }
    public DbSet<power_installation> PowerInstallations { get; set; }
    public DbSet<power_inverter> PowerInverters { get; set; }
    public DbSet<power_string> PowerStrings { get; set; }
    public DbSet<power_stringhistory> PowerStringHistorys { get; set; }
}

public class power_combiner
{
    [ScaffoldColumn(false)]
    public int id { get; set; }

    [Required]
    [DisplayName("Name")]
    [StringLength(128, ErrorMessage = "The 'name' cannot be longer than 128 characters")]
    public string name { get; set; }

    [Required]
    [DisplayName("Mac Address")]
    [StringLength(24, ErrorMessage = "The 'mac' cannot be longer than 24 characters")]
    public string mac { get; set; }

    [DisplayName("Location")]
    [StringLength(512, ErrorMessage = "The 'name' cannot be longer than 512 characters")]
    public string location { get; set; }

    [DisplayName("power_installation")]
    public int? installation_id { get; set; }

    [DisplayName("power_inverter")]
    public int? inverter_id { get; set; }

    [DisplayName("power_coordinator")]
    public int coordinator_id { get; set; }

    [DisplayName("Installation ID")]
    public virtual power_installation installation_ { get; set; }

    [DisplayName("Inverter ID")]
    public virtual power_inverter inverter_ { get; set; }

    [DisplayName("Coordinator ID")]
    public virtual power_coordinator coordinator_ { get; set; }
}

public class power_combinerhistory
{
    [ScaffoldColumn(false)]
    public int id { get; set; }

    [Required]
    [DisplayName("Voltage")]
    public double voltage { get; set; }

    [Required]
    [DisplayName("Current")]
    public double current { get; set; }

    [Required]
    [DisplayName("Temperature")]
    public double temperature { get; set; }

    [Required]
    [DisplayName("DateTime")]
    public DateTime recordTime { get; set; }

    [Required]
    [DisplayName("power_combiner")]
    public int combiner_id { get; set; }

    [DisplayName("Combiner ID")]
    public virtual power_combiner combiner_ { get; set; }
}

public class power_coordinator
{
    [ScaffoldColumn(false)]
    public int id { get; set; }

    [Required]
    [DisplayName("Mac Address")]
    [StringLength(24, ErrorMessage = "The 'mac' cannot be longer than 24 characters")]
    public string mac { get; set; }

    [Required]
    [DisplayName("Report Time")]
    public DateTime reportTime { get; set; }

    [Required]
    [DisplayName("Command")]
    [StringLength(2, ErrorMessage = "The 'command' cannot be longer than 2 characters")]
    public string command { get; set; }

    [Required]
    [DisplayName("Collect Time")]
    public int collect_time { get; set; }

    [Required]
    [DisplayName("Interval Time")]
    public int interval_time { get; set; }

    [DisplayName("power_installation")]
    public int? installation_id { get; set; }

    [DisplayName("Installation ID")]
    public virtual power_installation installation_ { get; set; }
}

public class power_installation
{
    [ScaffoldColumn(false)]
    public int id { get; set; }

    [Required]
    [DisplayName("Name")]
    [StringLength(128, ErrorMessage = "The 'name' cannot be longer than 128 characters")]
    public string name { get; set; }

    [Required]
    [DisplayName("UUID")]
    [StringLength(36, ErrorMessage = "The 'uuid' cannot be longer than 36 characters")]
    public string uuid { get; set; }

    [DisplayName("Description")]
    [StringLength(512, ErrorMessage = "The 'description' cannot be longer than 512 characters")]
    public string description { get; set; }

    [DisplayName("History Time")]
    public int historytime { get; set; }
}

public class power_inverter
{
    [ScaffoldColumn(false)]
    public int id { get; set; }

    [Required]
    [DisplayName("Name")]
    [StringLength(128, ErrorMessage = "The 'name' cannot be longer than 128 characters")]
    public string name { get; set; }

    [Required]
    [DisplayName("UUID")]
    [StringLength(36, ErrorMessage = "The 'uuid' cannot be longer than 36 characters")]
    public string uuid { get; set; }

    [Required]
    [DisplayName("Location")]
    [StringLength(512, ErrorMessage = "The 'location' cannot be longer than 512 characters")]
    public string location { get; set; }

    [DisplayName("power_installation")]
    public int installation_id { get; set; }

    [DisplayName("power_coordinator")]
    public int coordinator_id { get; set; }

    [DisplayName("Installation ID")]
    public virtual power_installation installation_ { get; set; }

    [DisplayName("Coordinator ID")]
    public virtual power_coordinator coordinator_ { get; set; }
}

public class power_string
{
    [ScaffoldColumn(false)]
    public int id { get; set; }

    [Required]
    [DisplayName("UUID")]
    [StringLength(36, ErrorMessage = "The 'uuid' cannot be longer than 36 characters")]
    public string uuid { get; set; }

    [Required]
    [DisplayName("Position")]
    public int position { get; set; }

    [DisplayName("Name")]
    [StringLength(128, ErrorMessage = "The 'name' cannot be longer than 128 characters")]
    public string name { get; set; }

    [DisplayName("Location")]
    [StringLength(512, ErrorMessage = "The 'location' cannot be longer than 512 characters")]
    public string location { get; set; }

    [Required]
    [DisplayName("power_combiner")]
    public int combiner_id { get; set; }

    [DisplayName("Combiner ID")]
    public virtual power_combiner combiner_ { get; set; }
}

public class power_stringhistory
{
    [ScaffoldColumn(false)]
    public int id { get; set; }

    [Required]
    [DisplayName("Current")]
    public double current { get; set; }

    [Required]
    [DisplayName("Record Time")]
    public DateTime recordTime { get; set; }

    [Required]
    [DisplayName("power_string")]
    public int string_id { get; set; }

    [DisplayName("String ID")]
    public virtual power_string string_ { get; set; }
}

EDIT

下面的代码是我所拥有的。我在日期转换方面遇到问题。当前上下文中不存在 GetTotalMilliseconds。它是来自 HighCharts 脚本还是来自我需要包含的其他名称空间?另外,我看起来是否正确使用数据上下文将数据分配给图表?我将 x 值更改为组合器 id:

.SetSeries(new[]
{
    new Series
    {
        Name = "Combiner",
        YAxis = 0,
        Data = new Data(powercombinerhistorys.Select(mm => new Point { X = mm.combiner_id,  Y = mm.current}).ToArray())
    }
});

我仍然收到错误。错误是:无法将类型“System.Int32”转换为类型“DotNet.Highcharts.Helpers.Number”。 LINQ to Entities 仅支持转换实体数据模型基元类型。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Drawing;
using DotNet.Highcharts;
using DotNet.Highcharts.Enums;
using DotNet.Highcharts.Helpers;
using DotNet.Highcharts.Options;
using Point = DotNet.Highcharts.Options.Point;
using AESSmart.Models;
using System.Data;
using System.Data.Entity;

namespace AESSmart.Controllers
{
    public class HighChartsTestController : Controller
    {
        private AESSmartEntities db = new AESSmartEntities();

        public ActionResult CombinerHistoryData()
        {
            var powercombinerhistorys = db.PowerCombinerHistorys.Include(p => p.combiner_);

            Highcharts chart = new Highcharts("chart")
            .InitChart(new Chart { DefaultSeriesType = ChartTypes.Column })
            .SetTitle(new Title { Text = "Combiner History" })
            .SetXAxis(new XAxis { Type = AxisTypes.Datetime })
            .SetYAxis(new YAxis
            {
                Min = 0,
                Title = new YAxisTitle { Text = "Current" }
            })
            .SetSeries(new[]
                       {
                           new Series
                           {
                               Name = "Combiner",
                               YAxis = 0,
                               Data = new Data(powercombinerhistorys.Select(x => new Point { X = GetTotalMilliseconds(x.recordTime),  Y = x.current}).ToArray())
                           }
                       });

            return View(chart);
        }
    }
}

据我了解,您需要一个图表来显示所有值(温度、电压、电流等)。我还在模型中看到你有 recordTime ,它可以是你的 xAxis 。这是示例代码:

Highcharts chart = new Highcharts("chart")
            .InitChart(new Chart { DefaultSeriesType = ChartTypes.Line })
            .SetTitle(new Title { Text = "Combiner History" })
            .SetXAxis(new XAxis { Type = AxisTypes.Datetime })
            .SetYAxis(new[]
                      {
                          new YAxis
                          {
                              Title = new YAxisTitle { Text = "Current" },
                              GridLineWidth = 1
                          },
                          new YAxis
                          {
                              Labels = new YAxisLabels { Formatter = "function() { return this.value +'°C'; }", },
                              Title = new YAxisTitle { Text = "Temperature" },
                              Opposite = true,
                              GridLineWidth = 0
                          },
                          new YAxis
                          {
                              Labels = new YAxisLabels { Formatter = "function() { return this.value +' V'; }" },
                              Title = new YAxisTitle { Text = "Voltage" },
                              Opposite = true,
                              GridLineWidth = 0
                          }
                      })
            .SetSeries(new[]
                       {
                           new Series
                           {
                               Name = "Current",
                               YAxis = 0,
                               Data = new Data(history.Select(x => new Point { X = GetTotalMilliseconds(x.recordTime), Y = x.current}).ToArray())
                           },
                           new Series
                           {
                               Name = "Temperature",
                               YAxis = 1,
                               Data = new Data(history.Select(x => new Point { X = GetTotalMilliseconds(x.recordTime), Y = x.temperature}).ToArray())
                           },
                           new Series
                           {
                               Name = "Voltage",
                               YAxis = 2,
                               Data = new Data(history.Select(x => new Point { X = GetTotalMilliseconds(x.recordTime), Y = x.voltage}).ToArray())
                           }
                       });

And the result is the following diagram: enter image description here

您可能感兴趣的第二个图表是柱形图,它将两次测量的当前值与记录的时间进行比较。这是示例代码:

Highcharts chart = new Highcharts("chart")
            .InitChart(new Chart { DefaultSeriesType = ChartTypes.Column })
            .SetTitle(new Title { Text = "Combiner History" })
            .SetXAxis(new XAxis { Type = AxisTypes.Datetime })
            .SetYAxis(new YAxis
            {
                Min = 0,
                Title = new YAxisTitle { Text = "Current" }
            })
            .SetSeries(new[]
                       {
                           new Series
                           {
                               Name = "Combiner",
                               YAxis = 0,
                               Data = new Data(combinerhistories.Select(x => new Point { X = GetTotalMilliseconds(x.recordTime), Y = x.current}).ToArray())
                           },
                           new Series
                           {
                               Name = "String",
                               YAxis = 0,
                               Data = new Data(stringhistories.Select(x => new Point { X = GetTotalMilliseconds(x.recordTime), Y = x.current}).ToArray())
                           }
                       });

And here is the chart on the page: enter image description here

我希望这对您有帮助。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

HighCharts -- MVC 3 数据库 的相关文章

  • Highcharts xAxis 钻取未正确更改

    http jsfiddle net ZBXV7 2 http jsfiddle net ZBXV7 2 when I click a column or label the xAxis write incorrect label but t
  • Highcharts重绘不重绘数据

    我一直在玩Highcharts v3 0 10 在网页上呆了一周 打印页面时无法重新绘制图表 问题是我在图表中使用深色背景颜色 但在打印时 我想将其更改为白色 为了实现这一点 我需要redraw 更改后我的图表backgroundColor
  • HighChart:多个图表的绘图线单击事件

    我正在使用 highchart 来实现一些向下钻取功能 我有一个功能可以让用户单击面积图并添加一条线 但后来我发现我的函数有一个错误 这些图表之间应该只有一条红线 但是当用户单击另一个图表时 第一个图表上的现有红线不会被删除 以下是我分享的
  • 将附加数据添加到 Highcharts 上的饼图工具提示中

    我正在尝试使用 highcharts 将附加数据添加到我的饼图中 尝试解释一下 我有一个浏览器饼图 火狐 10 铬 12 探索者 65 歌剧 13 我想添加更多信息以在工具提示中显示 例如 火狐 10 其中女性用户 5 铬 12 其中女性用
  • 如何在 R 中设置 highchart 全局选项

    我在 javascript 中看到了很多示例 但我找不到在 R 中执行此操作的示例 这是 API 链接 http api highcharts com highcharts global http api highcharts com hi
  • highcharts 弄错了我的时间

    highcharts 弄错了我的时间 我来自委内瑞拉 以防万一 我正在做一个实时系统 我可以在数据库中获取时间 秒和毫秒 例如 10 39 09 2 我应用 strtotime time 然后通过 json 发送到图表 在我的高图表中 我进
  • Highcharts:仅针对单个系列的工具提示

    我的系列中有 3 个数据集 低 正常 高 显示在散点图上 如何强制仅对普通数据集启用工具提示和标记 非常感谢 格式化程序 功能用于格式化工具提示文本的回调函数 返回 false 以禁用系列上特定点的工具提示 参考 http api high
  • 使用 Highcharts 和 React 创建条形图 - 出现未找到渲染 div 的错误

    我正在尝试在我的 Web 应用程序中使用 Highcharts 创建条形图 该应用程序在前端使用 React 下面是我的仪表板 tsx 文件的片段 我基本上只是从 JSFiddle 复制并粘贴了代码 http jsfiddle net 8q
  • 创建超过 2 组的高图表密度

    我尝试用两个以上的组创建高图表密度 我找到了一种手动将它们逐一添加的方法 但必须有更好的方法来处理组 示例 我想创建一个类似于下面的ggplot图表的highchart 而不需要将它们一一添加 有什么办法可以做到吗 d f lt data
  • 将模型从一个动作传递到同一控制器中的另一动作

    我正在尝试通过我的模型List 语句列表从一个操作到另一个操作 但我在第二个控制器中收到空值 请提出这里有什么问题 甚至尝试过 return RedirectToAction WriteInTemplate new statementLis
  • 图例中标签的悬停样式

    如何设置图例中标签的悬停样式 如果可以设置的话cursor default在此示例中 将鼠标悬停在 东京 纽约 柏林 伦敦 标签上http www highcharts com demo http www highcharts com de
  • 以编程方式在 Highcharts 中使用缩放绘制矩形和线条

    我正在使用 Highcharts 进行一些编程绘图Highcharts Renderer http api highcharts com highcharts Renderer using path and rect 在下面的代码中 我手动
  • highcharts图表重绘方法不刷新图表

    我很好奇为什么按钮 2 不起作用example http jsfiddle net uKWQ9 1 在这个 jsfiddle 示例中 附加到按钮 1 的 更新 方法正在工作 但在我的原始代码中 更新 也不起作用 它显示错误 对象 没有方法
  • 滚动高图图表

    这是我的问题 我正在使用phonegap框架来开发一个混合应用程序 并且我需要这个应用程序具有我决定使用highcharts库的图表 问题是 我似乎无法在触摸图表后滚动 至少在触摸图像的选定部分内部时 我想要做的是防止图表发生任何事件 并显
  • 设置股票数据 Highcharts xAxis 的格式

    我已经浏览了需要为 xAxis 属性设置的 Highcharts 选项来格式化时间标签 但没有运气了解这对于这种情况到底是如何工作的 我在白天 盘中 检索了股票的动态数据 我需要显示这些数据 因为检索的数据每天从 9 30 开始到 17 0
  • Highcharts 3.0 气泡图——控制气泡大小

    在 Highcharts 3 0 中 可以创建 气泡 类型的图表 而在 3 0 之前 必须使用 散点 图表并修改标记大小才能制作气泡图 旧方法的好处是您可以完全控制每个气泡的可见像素半径 新的气泡图会自动调整气泡的大小 以便它们相对于彼此调
  • MVC 3 不会提供 Areas 子文件夹中的内容文件

    我有一个 MVC3 应用程序 其中有几个区域和一个可移植区域 使用 MVCContrib 通常 我将所有内容文件保存在 Content 下 将脚本保存在 Scripts 下 然而 我正在为我的网站上的另一个服务构建一个相当复杂的网络客户端
  • 需要为每个图例文本高图应用背景颜色

    正如我在问题中所说 我希望改变我的传奇 例如 FROM TO 我已经尝试过这个背景颜色 legend backgroundColor CCC layout horizontal floating true align left vertic
  • HighCharts - 条形图中的 Y 轴填充

    我使用一种 y 轴标签样式 其中每个数字左对齐放置在其各自水平网格线的顶部 如下图所示 HighCharts 中唯一的复杂之处是轴标签有时会与柱形图中的第一列重叠 更新的演示 有关示例 请参见此图表 http jsfiddle net NW
  • 如何在 Highcharts / Highstock 上显示 x 轴上的十字线选定值和 y 轴上选定的日期?

    我正在研究这个项目 其中包括在交互式图表上显示历史数据 我得出的结论是 Highcharts Highstock 是最好的选择 因为它提供了最多的定制选项 我想要实现的目标是 当我将鼠标悬停在一个点上时 分别在 x 轴和 y 轴上显示所选值

随机推荐

  • 基于其他规则应用 CSS 规则 - RTL 特定样式

    推介会 我正在尝试建立一个可用于多种文化 具有不同阅读方向的网站 为此 我只需添加dir rtl 我的根 HTML 元素上的属性 我的问题是 我有一些特定于一个方向或另一个方向的 CSS 规则 大多数情况下是边距或填充 尝试使用属性选择器失
  • 编码 - codePointCount 和 length 之间的结果不同

    我发现了一个棘手的地方 但找不到任何答案为什么会发生这种情况 主要问题是字符串有多长 它是否包含一个或两个字符 Code public class App public static void main String args throws
  • 如何在 Travis CI 中使用 python-openbabel?

    我使用 Travis CI 作为毒理学绘图项目的一部分 对于这个项目 我需要 python openbabel 作为依赖项 因此 我已将 apt get 安装程序添加到 travis yml 文件中 如下所示 已删除注释 language
  • 在matlab中计算闭合曲线(或多边形)的曲率

    考虑以下几点 x 1 34 0 92 0 68 0 25 0 06 0 34 0 49 0 72 0 79 0 94 1 35 0 35 0 54 0 68 0 84 1 20 1 23 1 32 1 34 y 0 30 0 43 0 90
  • 如何快速混合 RGBA 无符号字节颜色?

    我正在使用 c 我想使用以下代码进行 alpha 混合 define CLAMPTOBYTE color if color 255 color BYTE color gt gt 31 else color BYTE color define
  • 创建DIBection失败

    BITMAPINFO bmi memset bmi 0 sizeof BITMAPINFO bmi bmiHeader biSize sizeof BITMAPINFOHEADER bmi bmiHeader biWidth m pImg
  • NOT EXISTS 和 COUNT(*) 之间的区别

    我在两个我认为等效的语句之间得到了不同的响应 SELECT COUNT vs NOT EXISTS 在大约 50 次执行中的 49 次中 这两个语句的行为相同 但有时却不然 我的猜测是 这些语句处理锁定页面或处理更 遥远 的事情的方式之间存
  • 将到期日期格式化为 mm/yy 格式

    您好 我正在编写一个编辑文本 其中我想要 MM YY 格式的信用卡到期日期 我要实现的算法如下 如果用户输入 2 到 9 之间的任何内容 我将文本输入更改为 02 到 09 如果用户输入 1 那么我等待下一个数字并检查 int 值月份是否小
  • 执行期间检测下溢

    有没有办法在执行过程中自动检测下溢 具体来说 我认为应该有一个编译器选项来生成代码 在可能导致下溢和类似错误的数学运算之后立即检查它们 我说的是 G 编译器 C99 C 11 具有浮点控制函数 例如fetestexcept 和定义的标志 包
  • 有人可以发布一个 Swift 中 MVC 模式的好例子吗? [关闭]

    Closed 这个问题正在寻求书籍 工具 软件库等的推荐 不满足堆栈溢出指南 help closed questions 目前不接受答案 一个实现了MVC模式的简单项目 到目前为止 我对它的情况有一个简单的了解 但我想看看实际的实现 这是
  • 从 Hive 表读取数据创建的 Spark DataFrame 的分区数

    我对 Spark 数据帧分区数量有疑问 如果我有 Hive 表 员工 其中包含列 姓名 年龄 ID 位置 CREATE TABLE employee name String age String id Int PARTITIONED BY
  • 从 github wiki 页面创建 gitbook

    我在 github wiki 中有很多文档 我想整理它并用它创作一本书 当我更新维基时 这本书也应该更新 这可能吗 欢迎来到 Gitbook 这项服务可能会对您有所帮助 https docs gitbook com integrations
  • jQuery 解析 XML 在 jQuery Mobile 列表中显示 UL UL 仅返回 XML 中的最后一项

    我正在使用 jQuery Mobile 1 1 1 和 jQuery 1 7 1 JQuery mobile 可以有一个嵌套列表 单击后可以在另一个屏幕中显示下一个 ul 看这个例子 我试图通过解析 XML 数据文件来做到这一点 我列出列表
  • Flutter如何更改ListTile中选定图块的背景颜色

    我正在尝试更改 ListTile 中选定图块的背景 我搜索并找到了以下两篇文章 但是它们都不能解决我的问题 Post1 https stackoverflow com questions 49331612 change background
  • 更改 Maven Archetype 中的包属性

    我创建了一个 Maven 原型 我的META INF maven archetype metadata xml看起来像这样
  • Univocity - 解析 CSV 时检测缺失列

    我正在使用 Univocity 库来解析 CSV 它工作得很好 但我需要一种方法来检测正在解析的文件的列数是否少于所需的列数 例如 如果我期望一个 3 列文件 其中列映射到 H1 H2 H3 那么我收到一个如下所示的文件 没有标题 V1 H
  • 从启动器菜单处理应用程序关闭事件

    我想做的是知道用户何时从 Android Launcher 的菜单关闭应用程序 长按主页按钮即可打开该菜单 我想在用户关闭应用程序时执行一些操作 实际上 我希望用户每次离开应用程序时都注销 但只要他也可以关闭应用程序 我就必须处理此事件 然
  • 支持库 24.2.1 中锚定 FloatingActionButton 的错误

    我从 24 2 0 开始就遇到这个问题 但现在我使用 24 2 1 这个错误仍然存 在 它只在 我有一个锚定的 FloatingActionButton 如下所示
  • isinstance('aaa', basestring) 和 isinstance('aaa', str) 有什么区别?

    a aaaa print isinstance a basestring true print isinstance a str true 在 3 0 之前的 Python 版本中 有两种字符串 纯字符串 和 unicode 字符串 纯字符
  • HighCharts -- MVC 3 数据库

    我正在 Visual Studio 2010 中使用 DotNet Highcharts 我正在创建一个 MVC 3 Web 应用程序 我可以通过静态分配数据来使 HighCharts 工作 我希望能够将数据从数据库发送到 HighChar